I need to read a json file with jsoncpp library.
I have this file:
{"one":false,"two":[{"id":"first"},{"id":"second"}],"three":550}
If i need to read only the first id of "two" element, i use:
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();
It works fine in Linux, but when i try it in Windows i have this error:
error: ambiguous overload for 'operator[]' in 'root.Json::Value::operator[](((const char*)"two"))[0]'
Why it happens and how can i fix this? Thanks.
Solved: There are two operator[]
, one with an int
as parameter and other with a const char
as parameter, and the compiler doesn't know who to use in Windows, but yes in Linux. Now i use [0u]
instead [0]
to indicate a number as parameter and it works fine.
This drove me crazy, until I stumbled upon this question, I mysteriously figured it out: Just cast it to Json::Uint (for some reason), or use 'u':
MapEvent::MapEvent(Json::Value& val)
{
operator_enum = val.get(0u, "").asString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With