Error: invalid conversion from 'const char*' to 'int' [-fpermissive]
Let’s say you have the following JSON to parse:
{
"modules": [
{
"name": "hello",
"id": 10
},
{
"name": "world",
"id": 20
}
]
}
If you write the following program:
JsonObject& root = jsonBuffer.parseOject(input);
JsonArray& modules = root["modules"];
const char* name = modules["hello"][0];
You’ll get the following compilation error:
error: invalid conversion from 'const char*' to 'size_t {aka unsigned int}' [-fpermissive]
This is because modules
is an array of object, as such it’s indexed by an integer, not by a string.
The solution is:
const char* name = modules[0]["hello"];
See: