Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<libjson/libjson.h>
- #include<libjson/JSONOptions.h>
- using namespace std;
- void ParseJSON(const JSONNode & n){
- JSONNode::const_iterator i = n.begin();
- while (i != n.end()){
- // recursively call ourselves to dig deeper into the tree
- if (i -> type() == JSON_ARRAY || i -> type() == JSON_NODE){
- ParseJSON(*i);
- }
- // get the node name and value as a string
- std::string node_name = i -> name();
- // find out where to store the values
- if (node_name == "RootA"){
- rootA = i -> as_string();
- }
- else if (node_name == "ChildA"){
- childA = i -> as_string();
- }
- else if (node_name == "ChildB")
- childB = i -> as_int();
- //increment the iterator
- ++i;
- }
- }
- int main()
- {
- cout<<"hi";
- std::string json = "{\"RootA\":\"Value in parent node\",\"ChildNode\":{\"ChildA\":\"String Value\",\"ChildB\":42}}";
- JSONNode n = libjson::parse(json);
- ParseJSON(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement