Jsoncpp is used by the client, so I learned jsoncpp as required by the project. I have never used xml before, but I feel that it is quite useful when I come into contact with json.
Reference address http://jsoncpp.sourceforge.net/class_json_1_1_value.html
# Include <QtCore/QCoreApplication>
# Include <json/json. h>
# Include <string>
Using std: string;
Int main (int argc, char * argv [])
{
Json: Reader reader;
Json: Value json_object;
Const char * json_document = "{/" age/": 26,/" person/": [{/" id/": 1,/" study /": [{/"language/":/"chinese/"}],/"name/":/"chen/"}, {/"id/": 2, /"name/":/"zhang/"}],/"name/":/"huchao /"}";
If (! Reader. parse (json_document, json_object) // read the string and convert it to json format
Return 0;
Int a1 = 0;
Json_object ["name"] = "wang"; // modify data
Json_object ["person"] [a1] ["study"] [a1] ["language"] = "English ";
Std: cout <json_object ["name"] <std: endl; // read data
Std: cout <json_object ["person"] [a1] ["study"] [a1] ["language"] <std: endl;
Std: cout <json_object ["age"] <std: endl;
Json: Value json_object;
Json_object.append ("11"); // Add the array format
Json_object.append ("12 ");
Json_object.append ("13 ");
Return a.exe c ();
}
Download jsoncpp and the program contains the jsoncpp source code.