小编Rag*_*ull的帖子

如何使用jsoncpp读取多个json对象

我有一个示例文件"sample.json",其中包含3个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= …
Run Code Online (Sandbox Code Playgroud)

c++ json jsoncpp

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

json ×1

jsoncpp ×1