小编Saf*_*fej的帖子

JsonCpp只在Windows中出现模糊过载

我需要用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();
Run Code Online (Sandbox Code Playgroud)

它在Linux中工作正常,但是当我在Windows中尝试时,我有这个错误:

error: ambiguous overload for 'operator[]' in 'root.Json::Value::operator[](((const char*)"two"))[0]'

为什么会发生这种情况?如何解决这个问题?谢谢.

解决:有两个operator[],一个带有intas参数,另一个带有const charas参数,编译器不知道在Windows中使用谁,但在Linux中是.现在我用[0u]而来[0]表示一个数字作为参数,它工作正常.

c++ windows json overloading ambiguous

5
推荐指数
1
解决办法
1263
查看次数

标签 统计

ambiguous ×1

c++ ×1

json ×1

overloading ×1

windows ×1