|
Boost Users : |
Subject: Re: [Boost-users] JSON Property file reader compile problem
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2011-08-13 05:57:58
On 10.08.2011, at 03:34, Scott Smith wrote:
> Im trying to use the boost property tree to read a json file. Im using 1.46 on gcc 4.6 (Fedora 15). Im also running on Eclipse (Indigo) which is relevant for something I mention below.
>
> Heres the issue . I have a JSON file which has an array of parameters which looks something like:
> {
> config:
> {
> modules:
> [
> {
> name: somename0,
> param1: someparam,
> param2:someotherparm
> },
> {
> name: somename1,
> param1: someparam,
> param2:someotherparm
> },
> {
> name: somename2,
> param1: someparam,
> param2:someotherparm
> }
> ]
> }
> }
>
> So, I wrote the following code (Note that I cant use boost:FOR_EACH because of some bug in eclipse (#332278) which causes an erroror so I believe):
>
> ptree v = pt.get<ptree>(config.modules);
This is wrong. You don't use get() for getting a subtree, you use get_child(). This call is guaranteed to fail at runtime, if not at compile time.
> for (ptree::iterator it = v.begin() ; it != v.end ; ++it)
> {
> ptree module = ???;
> }
>
>
> The first two lines seem to compile fine. Im assuming that what I get from v is the root ptree (the parent) for the various modules objects and that the iterator will walk through them. However, Ive tried all sorts of things trying to get at the module data (e.g., it->second
This one ought to work. If it doesn't, please post the error message. However, you should capture it in a reference, not make a copy - deep-copying ptrees is pretty expensive.
Sebastian
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