Any idea how I can either correctly extract data from the JSON string below or better format my JSON string so that it is more compatible with the JSON parser? The JSON string (shown below) has been post processed on a separate server that we are running internally, so we have control over the formatting.
Presently, I get NULL for the value of sensor
when using the code shown below. But when I use the commented JSON string and commented reference, I get the correct value.
#include <ArduinoJson.h>
//char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
char json[] = "{\"data\": [{\"time\": 26, \"headsign\": \"Wellington via Veterans Senior Center\", \"id\": \"38428504\"}, {\"time\": 36, \"headsign\": \"Wellington\", \"id\": \"38428529\"}, {\"time\": 56, \"headsign\": \"Wellington\", \"id\": \"38428543\"}, {\"time\": 74, \"headsign\": \"Wellington\", \"id\": \"38428494\"}]}";
StaticJsonBuffer<500> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
void tickTock() {
//const char* sensor = root["sensor"];
const char* sensor = root["data"][0]["id"];
Particle.publish("sensor", sensor);
Serial.println(sensor);
}
Timer timer(5000, tickTock);
void setup() {
timer.start();
}