Hi,
I am using the ArduinoJSON library and I am heaving troubles to use it for my JSON response I get from a server.
My JSON response:
{"results":[{"series":[{"name":"sensors","columns":["time","last"],"values":[["1970-01-01T00:00:00Z",1.57]]}]}]}
My code:
void parseJSON(char json[]){
Serial.println("to parse: " + String(json));
StaticJsonBuffer<500> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
if (!root.success()) {
Serial.println("parseObject() failed");
return;
} else{
Serial.println("parseObject() successful");
}
JsonObject& ooo = root["results"];
if (!ooo.success()) {
Serial.println("parseObject() failed");
return;
} else{
Serial.println("parseObject() successful");
}
//const char* test = root["results"];
//long time = root["results"]["series"][0];
//const char* kWh = root["series"]["values"][1];
const char* kWh1 = ooo["results"]["series"]["values"][1];
double kWh2 = ooo["series"]["values"][1];
//Serial.println(String(kWh));
Serial.println(String(kWh1));
Serial.println(kWh2);
}
My code prints the correct JSON at the beginning of my function and the JSON gets parsed successfully. So the buffer is big enough. But I have not found a solution to get to the number 1.57
at the end of the JSON.
I would be very grateful if you could help me to solve this problem and to learn how to parse JSON data.
Kind regards,
Tom