我需要使用 jsoncpp 库读取一个 json 文件。
我有这个文件:
{"one":false,"two":[{"id":"first"},{"id":"second"}],"three":550}
如果我只需要读取“two”元素的第一个 id,我使用:
std::string contents; //Contain the file
Json::Value root;
Json::Reader reader;
reader.parse(contents, root, false);
std::string aux = root["two"][0]["id"].asString();
它在 Linux 中运行良好,但当我在 Windows 中尝试时出现此错误:
错误:'root.Json::Value::operator[](((const char*)"two"))[0]' 中 'operator[]' 的不明确重载
为什么会发生这种情况,我该如何解决?谢谢。
已解决:有两个operator[]
,一个以int
为参数,另一个以const char
为参数,并且编译器不知道在 Windows 中使用谁,但在 Linux 中是。现在我使用 [0u]
而不是 [0]
来指示一个数字作为参数并且它工作正常。
最佳答案
这把我逼疯了,直到我偶然发现这个问题,我才神秘地想通了: 只需将其转换为 Json::Uint(出于某种原因),或使用 'u':
MapEvent::MapEvent(Json::Value& val)
{
operator_enum = val.get(0u, "").asString();
}
关于c++ - 仅在 Windows 中的 JsonCpp 模糊重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18901781/