fork download
  1. #include <sstream>
  2. #include <iostream>
  3. #include <boost/property_tree/ptree.hpp>
  4. #include <boost/property_tree/json_parser.hpp>
  5.  
  6. namespace pt = boost::property_tree;
  7.  
  8. std::string ss = "{ \"item1\" : 123, \"item2\" : 456, \"item3\" : 789 }";
  9.  
  10. int main()
  11. {
  12. // Read json.
  13. pt::ptree pt2;
  14. std::istringstream is(ss);
  15. pt::read_json(is, pt2);
  16. std::cout << "item1 = \"" << pt2.get<std::string>("item1") << "\"\n";
  17. std::cout << "item2 = \"" << pt2.get<std::string>("item2") << "\"\n";
  18. std::cout << "item3 = \"" << pt2.get<std::string>("item3") << "\"\n";
  19. }
  20.  
Success #stdin #stdout 0s 3320KB
stdin
Standard input is empty
stdout
item1 = "123"
item2 = "456"
item3 = "789"