3
これはJSONファイルです。Boostライブラリを使用してC++でJSONのコンテンツを取得する
{
"found":3,
"totalNumPages":1,
"pageNum":1,
"results":
[
{
"POSTAL":"000000"
},
{
"POSTAL":"111111"
},
{
"POSTAL":"222222"
}
]
}
ここにはC++コードがあります。
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <iostream>
int main()
{
// Short alias for this namespace
namespace pt = boost::property_tree;
// Create a root
pt::ptree root;
// Load the json file in this ptree
pt::read_json("filename.json", root);
std::vector< std::pair<std::string, std::string> > results;
// Iterator over all results
for (pt::ptree::value_type &result : root.get_child("results"))
{
// Get the label of the node
std::string label = result.first;
// Get the content of the node
std::string content = result.second.data();
results.push_back(std::make_pair(label, content));
cout << result.second.data();
}
}
私は親("results"
)に存在しますが、それは空白を出力子値の各セットを取得する必要があります。私は使用しようとしました
root.get_child("results.POSTAL")
しかし、角括弧のため、エラーが発生します。何かアドバイス?
これは役立つはずhttp://stackoverflow.com/questions/17124652/how -can-i-parse-json-arrays-with-c-boost –
コピーを習慣に入れてください正確なエラーメッセージを質問に追加します。 –