wangxiaowei0303 / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

Problem with FindMeber #121

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi to all!!!

I have a JSON string like this:

{"callCommand":{"command":"car","floor":"2","landing":"front"}}

Now, I would like to check if there is a name called "command" and get the 
value. Is it possible? My code is as follow, but it doesn't work.

/************** CODE ****************/
const char json[] = 
"{\"callCommand\":{\"command\":\"car\",\"floor\":\"2\",\"landing\":\"front\"}}";
rapidjson::Value::ConstMemberIterator itr = d.FindMember("command");
if (itr != d.MemberEnd())
    printf("command = %s\n", d["callCommand"]["command"].GetString());

Thank you in advance

Original issue reported on code.google.com by masssk...@gmail.com on 5 May 2015 at 9:14

GoogleCodeExporter commented 9 years ago
Uppsssss, sorry if this is not the forum to solve these kinds of problems.

Original comment by masssk...@gmail.com on 5 May 2015 at 9:15

GoogleCodeExporter commented 9 years ago
You need to find the value one level by one level.

Or you can try the new JSON Pointer feature: 
http://miloyip.github.io/rapidjson/md_doc_pointer.html

So that it can be simply

if (Value* v = GetValueByPointer(d, "/callCommand/command"))
    printf("command = %s\n", v->GetString());

Original comment by milo...@gmail.com on 5 May 2015 at 9:44