Can't parse nested JSON on the ESP
Posted: Fri Jun 26, 2015 3:50 pm
I'm using an ESP01 with the Arduino IDE (1.6.4). I'm trying to parse some JSON with the ArduinoJson library and have had lots of trouble. By now I've narrowed it down to this. I can parse this string:
but this one won't parse:
When I upload my sketch to an Arduino Mega both strings parse fine. Any ideas, anyone?
Here's the complete sketch:
Code: Select all
char json[] = "{\"1\":{\"lijn\":\"2 Kraayenstein\",\"min\":5}}";
but this one won't parse:
Code: Select all
char json[] = "{\"1\":{\"lijn\":\"2 Kraayenstein\",\"min\":5},\"2\":{\"lijn\":\"2 Leyenburg\",\"min\":18}}";
When I upload my sketch to an Arduino Mega both strings parse fine. Any ideas, anyone?
Here's the complete sketch:
Code: Select all
// werkt niet in esp, wel op mega!
#include <ArduinoJson.h>
void setup() {
Serial.begin(9600);
Serial.println("Here we go");
}
void loop() {
StaticJsonBuffer<200> jsonBuffer;
char json[] = "{\"1\":{\"lijn\":\"2 Kraayenstein\",\"min\":5},\"2\":{\"lijn\":\"2 Leyenburg\",\"min\":18}}";
JsonObject& root = jsonBuffer.parseObject(json);
if (!root.success()) {
Serial.println("parseObject() failed");
delay(500);
return;
}
const char* lijn = root["1"]["lijn"];
int mins = root["1"]["min"];
const char* lijn2 = root["2"]["lijn"];
int mins2 = root["2"]["min"];
Serial.println(lijn);
Serial.println(mins);
Serial.println(lijn2);
Serial.println(mins2);
delay(5000);
}