我正在构建一个从themoviedb.com获取电影信息的应用程序.该信息在JSON文件中提供.我正在尝试使用boost属性树存储信息.但有一点问题.
我通过以下代码说明了这个问题:
#include <vector>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
using namespace std;
using boost::property_tree::ptree;
class single_t{
int sID;
string sName;
public:
void setID(int ID){sID=ID;}
int getID(){return sID;}
void setName(string Name){sName=Name;}
string getName(){return sName;}
};
typedef vector<single_t*> multiple_t;
class foo{
string fTitle;
multiple_t fItems;
public:
string getTitle(){return fTitle;}
void setTitle(string Title){fTitle=Title;}
multiple_t getItems(){return fItems;}
void setItems(multiple_t Items){fItems = Items;}
void setItems(single_t Item){fItems.push_back(&Item);}
};
int main () {
try{
string response = "{\"title\":\"Foo\",\"items\":[{\"id\":123,\"name\":\"test1\"},{\"id\":456,\"name\":\"test2\"}]}";
ptree pt;
stringstream ss; ss << response;
read_json(ss, …Run Code Online (Sandbox Code Playgroud) 我想使用 Boost(属性树)库来解析以下有效的 JSON 文件:
{
"user": {
"userID": "5C118C8D-AA65-49C0-B907-348DE87D6665",
"dateProperty": "05-06-2015"
},
"challenges": [
{
"question#1": "answer",
"value": 5
},
{
"question": "answer",
"value": 5
},
{
"question": "answer",
"value": 5
},
{
"question": "answer",
"value": 5
},
{
"question": "answer",
"value": 5
},
{
"question": "answer",
"value": 5
},
{
"question": "answer",
"value": 5
},
{
"question": "answer",
"value": 5
},
{
"question": "answer",
"value": 5
},
{
"question": "answer",
"value": 5
}
] }
Run Code Online (Sandbox Code Playgroud)
我确实验证了 JSON 格式是正确的。
我还咨询了几个网站,例如: …