Jsoncpp the method to determine whether a field exists is as follows:
1) if (root["url"].type ()! = Json::nullvalue)
2) if (value["Sex"].isnull ())
Precautions
1) jsoncpp is a JSON library used by C + + to implement the syntax of JSON by overloading the brackets [], but because C + +
is a strongly typed language, jsoncpp in the implementation process, using a large number of assertions, if the type is encountered incorrectly
, the assertion is enforced, causing the program to exit
For example, pass the following string to the Jsoncpp
std::string strcontext = "Success": false, "MSG": "Gallium sentence switches arrival version ā æ 縞 ode:huoqushebeitongdaoshijianchuo11"
Json::reader read ();
Json::value Root;
if (NULL = = Read.parse (strcontext, Root)) return-1;
Although the string is not a proper JSON-formatted string, it will be parsed as well, resulting in a program that crashes, exits, and goes into the assertion, regardless of the field you use.
The solution is to specify strict JSON message parsing rules
std::string strcontext = "Success": false, "MSG": "Gallium sentence switches arrival version ā æ 縞 ode:huoqushebeitongdaoshijianchuo11"
Json::reader Read (Json::features::strictmode ());
Json::value Root;
if (NULL = = Read.parse (strcontext, Root)) return-1;
There won't be any anomalies like this.
Because Jsoncpp parses an illegal JSON, it is automatically fault-tolerant into character types. When a label is removed for a character type, the assert termination process is triggered.
Reference
Https://www.2cto.com/kf/201409/339350.html
http://blog.csdn.net/sxyizhiren/article/details/18625193
2) Json::value inside the function only Asint, asuint, and does not go to 64-bit integer function, so in the case of returning 64-bit integer, you can first convert to a string, using asstring, and then convert the string to 64-bit integer, indifferent night provides
One option is to convert to floating point, asdouble
Reference
Http://www.mamicode.com/info-detail-78967.html
Jsoncpp Use Experience