Rella
Rella

Reputation: 66945

Boost PropertyTree: How to read json array into?

So having such json:

{
  "config": {
    "name": "myconfig",
    "servecies": {
      "module": [
        "file",
        "Admin",
        "HR"
      ],
      "notModule": "MyNotModule"
    }
  }
}

How to parse module array into multimap<string,string>? and is it possible to find out if module is an array and notModule is not?

Upvotes: 0

Views: 1595

Answers (2)

Brian
Brian

Reputation: 1

The boost property tree includes a JSON parser.

boost::property_tree::json_parser::read_json("file.json", property_tree_root);

parses file.json and puts the root in property_tree_root.

The children in the property tree will have names, except those that are array elements.

This is essentially the same as: Parse elements from array in json file using boost

Upvotes: 0

Andrew Rasmussen
Andrew Rasmussen

Reputation: 15099

Use a JSON parser. There isn't really anything in C++ that will do all the work for you, you must use an external parser (or roll out your own) and interpret the events as it steps through.

I have had a good experience with jsoncpp, and there are a few others listed on json.org under the C++ section.

Upvotes: 3

Related Questions