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