Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsonCpp ambiguous overload only in Windows

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.

like image 801
Safej Avatar asked Oct 02 '22 22:10

Safej


1 Answers

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();
}
like image 199
Mazyod Avatar answered Oct 07 '22 19:10

Mazyod