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
精彩评论