Hello, I’m trying to parse a json using the library ArduinoJson.h, I havent had problems parsing the string called json, but when I get the srting form an SD card, in json2, and trie to parse it I recieve the “parseObject() failed” advice.
When I print json2 to see if there is any diference with the other variable I am obtaning these:
Comenzando la comunicación con la tarjeta SD
Se ha iniciado la comunicación correctamente
Información contenida en tarjeta.txt:
{“sensor”:“gps”,“time”:1351824120,“data”:[48.756080,2.302038]}
parseObject() failed
#include <SD.h>
#include<SPI.h>
int ss=4;
File Archivo;
#include <ArduinoJson.h>
//String json="{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
String json2;
void setup() {
StaticJsonBuffer<200> jsonBuffer;
Serial.begin(9600);
Serial.println("Comenzando la comunicación con la tarjeta SD");
pinMode(ss, OUTPUT);
if (!SD.begin(ss)) {
Serial.println("Se ha producido un fallo al iniciar la comunicación");
return;
}
Serial.println("Se ha iniciado la comunicación correctamente");
Archivo = SD.open("tarjeta.txt");
if (Archivo) {
Serial.println("Información contenida en tarjeta.txt: ");
int i =0;
while (Archivo.available()) {
char c=Archivo.read();
if (c==';'){
Serial.println(json2);
JsonObject& root = jsonBuffer.parseObject(json2);
if (!root.success()) {
Serial.println("parseObject() failed");
return;
}
const char* sensor = root["sensor"];
long time = root["time"];
double latitude = root["data"][0];
double longitude = root["data"][1];
Serial.println(sensor);
Serial.println(time);
Serial.println(latitude, 6);
Serial.println(longitude, 6);
}
json2.concat(c);
}
Archivo.close();
}
else {
Serial.println("El archivo datos.txt no se abrió correctamente");
}
}
void loop()
{
}
Thank You!