Jsoncpp Interface Summary

Source: Internet
Author: User

Value type Summary
enumvaluetype{Nullvalue=0,///< ' null ' valueIntvalue,///< signed integer valueUintvalue,///< unsigned integer valueRealvalue,///< Double valueStringValue,///< UTF-8 string valueBooleanvalue,///< bool valueArrayvalue,///< array value (ordered list)ObjectValue///< object value (collection of name/value pairs).};

Gets the type function in the Json::value function

Value Get function
Const Char*ascstring ()Const; std::stringAsstring ()Const; Int asint ()Const; UInt Asuint ()Const; Int64 AsInt64 ()Const; UInt64 AsUInt64 ()Const; Largestint Aslargestint ()Const; Largestuint Aslargestuint ()Const;floatAsfloat ()Const;DoubleAsdouble ()Const;BOOLAsbool ()Const;
Array type Operation array parsing
Json::value Root; Json::reader Reader; if (! Reader.parse (Str_data, Root)) {    //  Error processing} // It is important to note that if it is not an array type, the size function here returns the number of keys int array_size = root.size ();  for (i=0; i<array_size;i++) {    = root[i];     // Do something with obj}

When parsing an array, it is important to note that size () has a value returned when it is not an array type, and returns the number of keys in the JSON.

Building JSON Array types
Json::value Arrayjson;  for (iterator) {    json::value jsonobj;    jsonobj["a""b";    Arrayjson.append (jsonobj);}
Convert JSON to String
= Writer.write (root);

In general, JSON as a storage or network protocol, simple operation, good extensibility, but its disadvantage is also very obvious:

1. Binary data support is not good, often need to use Base64 to solve the problem;

2. Occupy large storage space, wasting disk and network bandwidth;

3. Low resolution efficiency;

Jsoncpp Interface Summary

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.