C ++-jsoncpp Learning

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.