
Hi -
I don't have the code in front of me, but we had to modify the grammar for
the JSON parser in boost property_tree in order to read top-level groups.
If you're familiar with boost spirit, I think it's not too much work.
Brian
On Mon, Dec 27, 2010 at 11:14 AM, Olivier Tournaire
Hi all,
I am currently trying to parse a JSON file, but cannot figure how to achieve this task (see for instance http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?term=sudoku&entity=software&limit=1 ). Here is a piece of code:
#ifndef ITUNES_JSON_STRUCTURE_HPP
#define ITUNES_JSON_STRUCTURE_HPP
#include
#include <string>
class itunes_json_structure
{
public:
void load(const std::string &filename);
boost::property_tree::ptree m_ptree;
};
#endif // ITUNES_JASON_STRUCTURE_HPP
#include "itunes_jason_structure.hpp"
#include
#include <iostream>
using namespace std;
void itunes_json_structure::load(const string &filename)
{
using boost::property_tree::ptree;
try
{
// Load the JSON file into the property tree. If reading fails
// (cannot open file, parse error), an exception is thrown.
read_json(filename, m_ptree);
cout << "resultCount = " << m_ptree.get<string>("resultCount") << endl;
ptree all_results = m_ptree.get_child("results");
// HERE!!! How can I read the content of the "results" node????
}
catch(exception &e)
{
throw e;
}
}
I am unable to read the content of the "results" node. Could you please give me some help?
Regards,
Olivier
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users