ArduinoJson: F.A.Q

Parsing succeeds but I can't read the values!

99.999% of the time, this is caused by a confusion between arrays and objects.

This often happens when the JSON contains [{ or :[.

Example 1:
[{"hello":"world"}]

Wrong implementation:

JsonObject& root = jsonBuffer.parseObject(json);
const char* world = root["hello"];

Good implementation:

JsonArray& root = jsonBuffer.parseArray(json);
const char* world = root[0]["hello"];
Example 2:
{"hello":["world"]}

Wrong implementation:

JsonObject& root = jsonBuffer.parseObject(json);
const char* world = root["hello"];

Good implementation:

JsonArray& root = jsonBuffer.parseArray(json);
const char* world = root["hello"][0];
Example 3:
{"hello":[{"new":"world"}]}

Wrong implementation:

JsonObject& root = jsonBuffer.parseObject(json);
const char* world = root["hello"]["new"];

Good implementation:

JsonArray& root = jsonBuffer.parseArray(json);
const char* world = root["hello"][0]["new"];

See:

Fork me on GitHub