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 ¤t = 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