我有一个包含 3 个 json 对象的示例文件“sample.json”
{"A":"something1","B":"something2","C":"something3","D":"something4"}{"A":"something5","B":"something6", "C":"something7","D":"something8"}{"A":"something9","B":"something10","C":"something11","D":"something12"}
(上面的文件中没有换行符)
我想使用 jsoncpp 读取所有三个 json 对象。
我能够读取第一个对象,但不能读取它之后。
这是我的代码的相关部分
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
std::ifstream test("sample.json", std::ifstream::binary);
bool parsingSuccessful = reader.parse(test, root, false);
int N = 3;
if (parsingSuccessful)
{
for (size_t i = 0; i < N; i++)
{
std::string A= root.get("A", "ASCII").asString();
std::string B= root.get("B", "ASCII").asString();
std::string C= root.get("C", "ASCII").asString();
std::string D= root.get("D", "ASCII").asString();
//print all of them
}
}