我有这段代码,需要解析或获取JSON数组作为std::string以便在应用程序中使用。
std::string ss = "{ \"id\" : \"123\", \"number\" : \"456\", \"stuff\" : [{ \"name\" : \"test\" }] }";
ptree pt2;
std::istringstream is(ss);
read_json(is, pt2);
std::string id = pt2.get<std::string>("id");
std::string num= pt2.get<std::string>("number");
std::string stuff = pt2.get<std::string>("stuff");
需要的是像这样作为std :: string检索"stuff"
[{ "name" : "test" }]
然而,上述代码中 stuff
只返回空字符串。可能出了什么问题?
ss = R"({ "id":"123", "number":"456", "stuff":[{"name":"test"}] })"
。 - Jarod42