JSON Parse issue

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
superg2
 
Posts: 41
Joined: Wed Aug 31, 2022 12:27 pm

JSON Parse issue

Post by superg2 »

I'm parsing JSON in my Arduino sketch and having issues. I think it has to do with escaping characters but not sure. I'm calling the web service from Adafruit QT PY using Python without any issues.

String wsResponse = clientHTTP.responseBody();
Serial.print("response: ");
Serial.println(wsResponse);

//prints {\"ResponseCode\":1,\"ResponseMessage\":\"Success\",\"LogID\":13106}

StaticJsonDocument<200> jsonBuffer; //40 is probably enough

char json[wsResponse.length()+1];
wsResponse.toCharArray(json, wsResponse.length()+1);

DeserializationError error = deserializeJson(jsonBuffer, json);
int wsResponseCode = jsonBuffer["ResponseCode"];

if test with the following text it works as expected
String wsResponse = "{\"ResponseCode\":1,\"ResponseMessage\":\"Success\",\"LogID\":13106}";
There are backslashes in the text, not sure why will display

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”