ブースト ライブラリから json_reader ptree にアクセスするために、私はあまりにも多くの時間を費やしてきました。
本当に頻繁にカプセル化されるjsonファイルがあります:(pseudo-json:)
"Foo": {
"nameofFoo:"foofoo"
"Bar": [{
"BarFoo":
{ BarFooDeep: {
BarFooDeepDeep: {
"BarFooValue1": 123
"BarFooValue2" : 456
}
}
}
"FooBar": [ {
"FooBarDeep" :[ {
FooBarDeepDeep:[ {
FooBarValue1: "ineedthis"
FooBarValue2: "andthis"
} ]
FooBarDeepDeep1:[ {
FooBarValue1: "ineedthis"
FooBarValue2: "andthis"
} ]
"FooBarDeep" :[ {
FooBarDeepDeep2:[ {
FooBarValue1: "ineedthis"
FooBarValue2: "andthis"
} ]
FooBarDeepDeep3:[ {
FooBarValue1: "ineedthis"
FooBarValue2: "andthis"
} ]
and so on .... won t complete this now...
これで、すべての FooBar の FooBarValue1 と FooBarValue2 を取得するだけで済みます。
ptree が配列を空の子 ("") と一緒に配置することは知っています
すべての子を再帰的に反復することで、すべてのメンバーにアクセスできます。
しかし、特別な値にアクセスするためのより良い方法はありませんか?
ptree find はどのように機能しますか? 私はいつもコンパイルエラーが発生します...
ptree jsonPT;
read_json( JSON_PATH, jsonPT);
ptree::const_iterator myIT = jsonPT.find("FooBarValue1");
double mlat = boost::lexical_cast<int>(myIT->second.data());
エラー: 'boost::property_tree::basic_ptree, std::basic_string >::assoc_iterator' から非スカラー型 'boost::property_tree::basic_ptree, std::basic_string >::const_iterator' への変換が ptree::const_iterator を要求しましたmyIT = jsonPT.find("FooBarValue1");
この ptree にアクセスするためのヒントを誰か教えてくれませんか?!?