help using arrays with libJSON
Is there anyone here who's experienced at using libjson who could give me a quick example by any chance? say i've got the following code
Code:
JSONNode root, child;
child.push_back(JSONNode("list", "array of strings goes here"));
child.push_back(JSONNode("access", 126353359));
child.set_name("root");
root.push_back(child);
I know it's extremely simplistic, it's just to give an example of what i'm trying to achieve. What I want to do is have an array of strings as a child node to 'list' but can't work out how to do this... Any help would be much appreciated...
Re: help using arrays with libJSON
Well, the way that you declare your list node:
Code:
child.push_back(JSONNode("list", "array of strings goes here"));
is making it a string.
Try this instead.
Code:
JSONNode list = JSONNode(JSON_ARRAY); //declare it as an array
list.set_name("list"); //name it "list"
child.push_back(list); //push it onto the child
...
//Now you can push strings into your list
JSONNode & array = child["list"]; //get a reference to the list
array.push_back(JSONNode("", "I am a string")); //no name because arrays don't have them
You can also populate your list before pushing it onto child, which is actually better. Because of reference counting, copying and pushing nodes is cheap.
I'm actually the maintainer and author of libjson so this is a good place to get help if you need it. ;) I also do watch the libjson forum on sourceforge
Re: help using arrays with libJSON
ahh yeah i get it now, then we just
Code:
list.push_back(JSONNode("", "whatever"));
to populate our array. Brilliant, thanks for that... Quickest reply ever. I did see your username floating around various places when I was sifting through google beforehand looking for an answer as it happends so I hoped if I posted here you'd answer :D Nice one
edit: just saw your edit on setting up the list beforehand, thanks for the example I'll probably go down that road.
Re: help using arrays with libJSON
No problem, I check this forum every day as well as sourceforge if you need any more help.