How to get JSON objects value using casablanca in C++ -
i new json. , m using codeplex (casablanca) reading json values.
below sample json string:
[{ "rollno": 2000, "name": "suhani","marks":{"grade":"c"} }, {"rollno": 3000,"name": "ishu", "marks":{ "grade":"a"} }]
the code access name & rollno, writing below code:
json::value jobj = json::value::parse(utility::conversions::to_string_t(resultbody)); (unsigned int = 0; < jobj.size(); i++) { auto getval = jobj[i]; if (getval.at(u("name")).is_string()) { auto xstr = getval.at(u("name")).as_string(); std::string wide = utility::conversions::to_utf8string(xstr); std::string str(wide.begin(), wide.end()); string name = str; } if (getval.at(u("rollno")).is_integer()) { auto xstr = getval.at(u("rollno")).as_integer(); int rollno = xstr; } }
how value @ grade ?? when access marks of type object, not getting how access grade there. please respond.
marks still json object. you'll need access grade property. code snippet add following:
(unsigned int = 0; < jobj.size(); i++) { auto getval = jobj[i]; auto marks_object = getval.at(u("marks")); auto grade_value = marks_object.at(u("grade")).as_string();
Comments
Post a Comment