Jsoncpp Article 2-API

Source: Internet
Author: User

For more api reference, see jsoncpp header file

1. A brief description of jsoncpp APIs

1. parse (convert JSON string to object)

STD: String strdatajson;

JSON: reader jreader;

JSON: Value jobject;

If (! Jreader. parse (strdatajson, jobject ))

{

Cerr <"parse JSON error." <Endl;

Return bsuccess;

}


2. Read

STD: String strmsg = JREC ["MSG"]. asstring ();

Int nretcode = JREC ["RET"] .. asint ();

JSON: Value jlist = JREC ["data"] ["list"];

Int nsize = jlist. Size ();


Get error message: jreader. getformatederrormessages ()


3. Add or modify

Jroot ["stringdata"] = JSON: Value ("MSG ");

Jroot ["intdata"] = JSON: Value (10 );


4. Delete

Jvalue. removemember ("toberemove ");


5. Convert the object into a string

JSON: fastwriter fast_writer;

Strjreclist = fast_writer.write (jroot );


// Formatted JSON with a carriage return line break

STD: String Strout = jroot. tostyledstring ();

Conversion from http://my.oschina.net/chenleijava/blog/144312

2. Detailed API

 
class JSONAPI_API JsonValue{typedef std::map<std::string, JsonValue*>InnerMap;typedef std::vector<JsonValue*>InnerVector;public:JsonValue();virtual ~JsonValue();public:void clear();//import/exportvoid parse(const char* jsonString);JsonString toString();JsonString toString_styled();void toFile(const char* filename);void toFile_styled(const char* filename);//setvoid operator=(JsonValue& jval);void operator=(char vInteger);void operator=(unsigned char vInteger);void operator=(short vInteger);void operator=(unsigned short vInteger);void operator=(long vInteger);void operator=(unsigned long vInteger);void operator=(int vInteger);void operator=(unsigned int vInteger);void operator=(__int64 vInteger);void operator=(unsigned __int64 vInteger);void operator=(float vReal);void operator=(double vReal);void operator=(bool vBoolean);void operator=(const char* vString);int append(JsonValue& jval);int append(char vInteger);int append(unsigned char vInteger);int append(short vInteger);int append(unsigned short vInteger);int append(long vInteger);int append(unsigned long vInteger);int append(int vInteger);int append(unsigned int vInteger);int append(__int64 vInteger);int append(unsigned __int64 vInteger);int append(float vReal);int append(double vReal);int append(bool vBoolean);int append(const char* vString);//getJsonValue& operator [](const char* name);JsonValue& operator [](unsigned int arrIdx0);//get final valuechargetChar();unsigned chargetUChar();shortgetShort();unsigned shortgetUShort();longgetLong();unsigned longgetULong();intgetInt();unsigned intgetUInt();__int64getInt64();unsigned __int64 getUInt64();boolgetBoolean();floatgetFloat();doublegetDouble();const char*getString();//checkbool isNull();bool isChar();bool isUChar();bool isShort();bool isUShort();bool isLong();bool isULong();bool isInt();bool isUInt();bool isInt64();bool isUInt64();bool isBoolean();bool isFloat();bool isDouble();bool isString();bool isObject();bool isArray();protected:ValueType m_valueType;union{__int64 m_integer;double m_real;bool m_boolean;char* m_string;InnerMap* m_kv;InnerVector* m_array;}m_v;protected:void setAsObject();void setAsArray();friend JValHelper;};

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.