Parsing JSON

Hello i have this code that is not working when i reach the parsing fucntion.
It tells me alway "parseObject() failed".
the value of Json String variable is :

{"id_operazione":"21871","id_circolo":"38","id_utente":"3","ora_prenotata":"2017-02-17 14:00:00","importo":"15","annullata":"0","campo":"1","data_operazione":"2017-01-21 20:45:56","testo_operazione":"","id_utente_2":"0","id_utente_3":"0","id_utente_4":"0","tipo_prenotazione":"0"}

Can you help me?


StaticJsonBuffer<300> jsonBuffer;

bool checkJson(String Campo)
{
while (client.connected() || client.available()) //connected or data available
{
char c = client.read(); //gets byte from wifi buffer
c = utf8ascii(c); // convert from utf8

///get JSON
if (c == '{') {
begin = true;
}

if (begin) response += (c);

if (c == '}') {
break;
}
delay(1);
}
Serial.println(response);

//deserializzo
char jsonText[response.length()];
response.toCharArray(jsonText,response.length());

JsonObject& root = jsonBuffer.parseObject(jsonText);
if (!root.success())
{
Serial.println("parseObject() failed");
client.flush();
client.stop();
Serial.println("-------------------");
return false;
}
TTOre_data data;
data.id_operazione = root["id_operazione"];
}

You haven't posted the whole code so can't be sure (e.g. where is 'response' declared, is it a String?).
But why have this:

delay(1);

..aren't you in danger of losing incoming characters while you wait here?

Serial.println(response);

what output does this give, is it the correct (unparsed) json?

Hi

i wrote in the question the JSON contained in the String.
The response is a String : String response = "";

i found the reason ...
i was missing a char...
adding +1 to the lenght was the solution...

char jsonText[response.length()+1];