Refer to:
1. https://github.com/DaveGamble/cJSON
2. https://github.com/aMonst/json_xml_transf
Example:
int main(int argc, _TCHAR* argv[])
{
std::string strXml;
std::string strJson =
"{\
\"url\": \"www.xxxx.com\",\
\"urlType\": 1,\
\"banner\": \"HTTP/1.1 200\",\
\"maliciousActType\": 5,\
\"discoveryTime\": \"2016-02-11 22:03:01\",\
\"updateTime\": \"2016-02-11 22:03:01\",\
\"infoSource\": \"Jesse Stone\",\
\"credit\": 70,\
\"fileMd5\": \"SDSDSDKSJDOOOwwww992329\",\
\"desc\": \"none\",\
\"customInfo\": {\
\"key1\": \"label_mark00\", \
\"key2\": \"label_mark01\"\
},\
\"UserNumber\": {\
\"Aman_id\": [60,61,62],\
\"Bman_id\": [70,71,72]\
},\
\"subject\":\
[{\
\"name\": \"Math\",\
\"score\": 0xA0\
},{\
\"name\": \"English\",\
\"score\": 88.5\
}]\
}";
FILE* fp00 = fopen("./text_xml.txt","wb");
FILE* fp01 = fopen("./test_json.txt","wb");
strXml = CJsonFace::Json2Xml(strJson);
fwrite(strXml.c_str(),1,strXml.size(),fp00);
fclose(fp00);
strJson = CJsonFace::Xml2Json(strXml);
fwrite(strJson.c_str(),1,strJson.size(),fp01);
fclose(fp01);
return 0;
}
Download:
http://www.mediafire.com/file/xcc75pf58hxdf4x/json2xml.zip
沒有留言:
張貼留言