Hey all oi want to parse this json datas but i can’t because of the structure , so i tried this :
...
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(payload);
StaticJsonBuffer<300> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(payload);
const char* code = root["code"];
const char* id = root["datas"][0];
const char* days = root["datas"][1];
const char* temp = root["datas"][2];
const char* hum = root["datas"][3];
Serial.println(code);
Serial.println(id);
Serial.println(days);
Serial.println(temp);
Serial.println(hum);
and when i print it :
1
Thank you all !
J-M-L
#2
Do you really feel you provided all the information to help us help you?
Assuming you enter the if - your first print is the payload si it feels it’s not a JSON format...
But that’s just a wild guess - my cristal ball is not working today
Sorry i forgot to past the json , yes the payload contains a json .
so this is the json data :
{
"success": true,
"code": "1",
"datas": [
{
"id": 1,
"days": 14,
"temp": 20,
"hum": 80
}
]
}
Update :
I found this example :
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(payload);
JsonArray& datas = root["datas"];
const char* code = root["code"];
for (auto& datas : datas) {
float id = datas["id"];
float days = datas["days"];
float temp = datas["temp"];
float hum = datas["hum"];
}
and :
error: use of 'datas' before deduction of 'auto'
for (auto& datas : datas) {
^
exit status 1
use of 'datas' before deduction of 'auto'
This website generates ArduinoJson code based on the JSON string you provide.