Boost logo

Boost Users :

Subject: [Boost-users] [property_tree] Parsing JSON
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2010-12-27 14:14:48


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 <boost/property_tree/ptree.hpp>

 #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 <boost/property_tree/json_parser.hpp>

 #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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net