Gerard-Meier

How to use the Json parser

Apr 16th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1.     // Source from: http://sourceforge.net/projects/cajun-jsonapi/
  2.  
  3.     std::stringstream jsonString("{ \"name\": \"gerjo\", \"age\": 24 } ");
  4.  
  5.     // Storage container for the to-be-read data:
  6.     json::Object data;
  7.  
  8.     // Read the jsonString into the storage container:
  9.     json::Reader::Read(data, jsonString);
  10.  
  11.     // Retrieve the values.
  12.     int age          = (json::Number) data["age"];
  13.     std::string name = (json::String) data["name"];
  14.  
  15.     std::cout << "Name is: " << name <<  " age is: " << age << std::endl;
Advertisement
Add Comment
Please, Sign In to add comment