Using Jsoncpp to convert a JSON string to a vector

Source: Internet
Author: User
In the course of API testing, it is often encountered that the incoming parameters are complex types, and under Python, it is customary to use dictionaries to represent complex types. But C + + string processing is more mentally retarded, in general C + + will use vector to store complex types, then there is the problem of conversion, the following small section of code to convert the string into a vector of the process to convert the string as follows: const char * Jsongroupinfo= "[{/" Groupid/": 946838524,/" groupname/":/" bababa/",/" mask/": 1,/" Parentid/": 946755072}]"; Json::reader Reader;
Json::value Json_object;
if (!reader.parse (Jsongroupinfo, Json_object))
Return "Parse jsonstr error";
Suserchggroup SUCG;
vector< suserchggroup > M_groupinfo;
for (int i = 0; i < json_object.size (); i + +)
{
Json::value &current = Json_object[i];
Sucg.m_groupid = current["GroupId"].asint ();
Sucg.m_groupname = current["GroupName"].asstring ();
Sucg.m_mask = current["Mask"].asint ();
Sucg.m_parentid = current["ParentID"].asint ();
M_groupinfo.push_back (SUCG);
In short, it turns it into an object and then stores the object in a vector.

Using Jsoncpp to convert a JSON string to a vector

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.