c++ - 为什么 JSON 对象不是数组?

标签 c++ json arrays

我的 JSON 文件如下所示:

{
"strings": {
    "keyone": "abc",
    "keytwo": "def",
    }
}

使用 C++,

const Json::Value strings = root["strings"];
for (int index = 0; index < strings.size(); index++) 
{
    std::cout << strings.isArray() << std::endl;
    std::cout << strings.get(index, "ERROR") << std::endl;
}

strings.IsArray() 返回 0,表示它不是数组。而第二行 strings.get(index, "ERROR)",在执行时就崩溃了,可能是因为我把它当作数组来使用,而实际上它不是。

所以我假设字符串只是一个字符串而不是数组。我怎样才能使它成为一个数组对象?

最佳答案

"strings.IsArray()" returns 0, saying it's not an array

当然可以,"strings":{ ... } 是 JSON 术语中的“对象”。

关于c++ - 为什么 JSON 对象不是数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11371724/

相关文章:

c++ - 如何从 Linux 编译到 SDL2 应用程序到 Windows?

C++/OpenGL - 2D - 如何在矩形边界框中剪辑一个圆

java - 迭代实现 Iterable<Item> 的类中数组的非空部分

c# - 在 C# 中使用带有字符串数组的 'foreach' 循环

javascript - 将 JSON 文件加载到 JavaScript 变量中

Java初学者: Array Bubble Sort

c++ - 如果在 C++ 模板库中使用禁用的库功能,则警告用户

c++ - 在回调函数中安全地删除调用者对象

c# - List<> 无法序列化为 JSON

android - "Not a primitive array"错误,当我尝试从 JSON 中拉出一个 child 时