makes it nice & easy to add arrays via looping, etc. you can also create 2D arrays (eg: arrays of arrays) easily in the same way, by looping appends onto the first/second/third/etc element in the array you just created.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I know that write StringValue and IntegerValue.
{
"account" : "javawork",
"serial" : 10
}
Json::Value writeValue;
writeValue["account"] = std::string("javawork");
writeValue["serial"] = 10;
but How do I write ArrayValue?
{
"friends":
[
"alice",
"rabbit",
"queen"
]
}
Hey Buddy!
By Any chance did u get this working. I am stuck with the same problem. Any help would be great.
Thanks
venkat
Some one might be interested.
Json::Value jValueRoot;
Json::Reader jReader;
_bstr_t sss = _T("[]");
if(jReader.parse((char *)(sss), jValueRoot))
{
if(jValueRoot.isArray()){
Json::Value widgetMem;
widgetMem["name"] = 'name';
Json::Value::UInt ii = jValueRoot.size();
jValueRoot[ii] = widgetMem;
Json::StyledWriter writer;
std::string output = writer.write( jValueRoot );
}
}
Thanks
venkat
I struggled a lot to do dis, but its actually quite easy :-)
Json::FastWriter w;
Json::Value root;
Json::Value::UInt index=0;
root["Features"][index]["test"]="null";
i had a momentary pause on this point too, but it's actually trivial.
use ".append" on the node you want to add an array to.
makes it nice & easy to add arrays via looping, etc. you can also create 2D arrays (eg: arrays of arrays) easily in the same way, by looping appends onto the first/second/third/etc element in the array you just created.
I know it's an old thread, but shouldn't be it:
Json::Value& friend_node = root["friends"];
friend_node.append("alice");
friend_node.append("rabbit");
friend_node.append("queen");
maybe better.
Thanks Paulik , your solution got me working.