我的 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/