开发者

Boost PropertyTree: How to read json array into?

开发者 https://www.devze.com 2023-03-20 00:46 出处:网络
So having such json: { \"config\": { \"name\": \"myconfig\", \"servecies\": { \"module\": [ \"file\", \"Admin\",

So having such json:

{
  "config": {
    "name": "myconfig",
    "servecies": {
      "module": [
        "file",
        "Admin",
        "HR"
      ],
      "notModule": "MyNotModul开发者_JAVA百科e"
    }
  }
}

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号