I haven't been able to read the content of the following JSON from the Value that was parsed,
I get an exception when I try to read key1 value see last line in code below,
the JSON input is:
{
"todo":
[
"work" :
{
"key1" : "value1",
"key2" : "value2",
}
]
}
this is the code that I use,
Json::Reader reader;
Json::Value root;
reader.parse(jsonString,root);
Json::Value todos = root["todo"];
if(!todos_.isArray())
{
return;
}
Json::Value::iterator itr = todos_.begin();
while (itr != todos_.end())
{
Json::Value single = (*itr);
string value = single["key1"];
}
please help !
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The JSON file itself has a small bug.
todo is an array and the first element in the array is a pair. Therefore the pair should be enclosed within the braces in order to show that the pair is the first element in the todo array.
I haven't been able to read the content of the following JSON from the Value that was parsed,
I get an exception when I try to read key1 value see last line in code below,
the JSON input is:
{
"todo":
[
"work" :
{
"key1" : "value1",
"key2" : "value2",
}
]
}
this is the code that I use,
Json::Reader reader;
Json::Value root;
reader.parse(jsonString,root);
Json::Value todos = root["todo"];
if(!todos_.isArray())
{
return;
}
Json::Value::iterator itr = todos_.begin();
while (itr != todos_.end())
{
Json::Value single = (*itr);
string value = single["key1"];
}
please help !
string value = single["key1"].asString();
The JSON file itself has a small bug.
todo is an array and the first element in the array is a pair. Therefore the pair should be enclosed within the braces in order to show that the pair is the first element in the todo array.
It should be
{
"todo":
[
{
"work" :
{
"key1" : "value1",
"key2" : "value2",
}
}
]
}