The problem: The array ends up empty.
Code: Select all
void GetListFromServerUsingArduinoJson(){
WiFiClient client;
//Skipping some code here: client.connect(), make request, receive response, parse out headers etc.
//So we're continuing with the response body... a string representation of a JSON Array:
String arrayStr;
char currentChar;
while(client.available()){
currentChar=client.read();
arrayStr.concat(currentChar);
}
Serial.println(arrayStr); // All working to this point. Result is "[\"Test1\",\"Test2\"]";
StaticJsonDocument<50> arrayObj;
DeserializationError Err=deserializeJson(arrayObj, arrayStr);
if(Err){
Serial.println("Array Test Failed"); //No error, so far so good.
}else{
int arrayLength=arrayObj.size();
Serial.println(arrayLength); //Problem here: shows 0. arrayObj is indeed empty
}
}
DeserializationError Err=deserializeJson(arrayObj, "[\"Test1\",\"Test2\"]");
Is the problem that that arrayStr is not a string literal or const String?
but if that's the case I'm not sure how to resolve the above issue.