Advertisement
Guest User

Untitled

a guest
Jan 19th, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include<iostream>
  2. #include<libjson/libjson.h>
  3. #include<libjson/JSONOptions.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. void ParseJSON(const JSONNode & n){
  9. JSONNode::const_iterator i = n.begin();
  10. while (i != n.end()){
  11. // recursively call ourselves to dig deeper into the tree
  12. if (i -> type() == JSON_ARRAY || i -> type() == JSON_NODE){
  13. ParseJSON(*i);
  14. }
  15.  
  16. // get the node name and value as a string
  17. std::string node_name = i -> name();
  18.  
  19. // find out where to store the values
  20. if (node_name == "RootA"){
  21. rootA = i -> as_string();
  22. }
  23. else if (node_name == "ChildA"){
  24. childA = i -> as_string();
  25. }
  26. else if (node_name == "ChildB")
  27. childB = i -> as_int();
  28.  
  29. //increment the iterator
  30. ++i;
  31. }
  32. }
  33.  
  34.  
  35. int main()
  36. {
  37. cout<<"hi";
  38.  
  39. std::string json = "{\"RootA\":\"Value in parent node\",\"ChildNode\":{\"ChildA\":\"String Value\",\"ChildB\":42}}";
  40. JSONNode n = libjson::parse(json);
  41. ParseJSON(n);
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement