Convert String from HTTP_GET to char array for JSON parse

Hi,

As the title suggests, I’m struggling to convert my string (returned from a HTTP_GET) to the correct format to parse it with JSON.

I get the error, “invalid conversion from ‘char*’ to ‘char’ [-fpermissive]”

If I copy the return from my HTTP_GET and hardcode it into the JSON parse function it works perfectly.

My code snippet is:

      String data = http.getString();
      char charBuf[512];
      data.toCharArray(charBuf, 512);
      char JSONMessage[] = {charBuf};
      StaticJsonBuffer<1200> JSONBuffer; //Memory pool
      JsonObject& parsed = JSONBuffer.parseObject(JSONMessage); //Parse message

Thanks,

Glenn

      char JSONMessage[] = {charBuf};

Why? You already have a char array with the JSON data in it.

      char charBuf[512];
      data.toCharArray(charBuf, 512);
      char JSONMessage[] = {charBuf};
      StaticJsonBuffer<1200> JSONBuffer; //Memory pool

Which Arduino are you running this code on? If the String instance can contain 512 characters plus the char array to hold 512 characters, that’s more than half the memory on an Arduino. There is NOT then room for a 1200 character buffer for parsing the JSON data.

I get the error, “invalid conversion from ‘char*’ to ‘char’ [-fpermissive]”

That’s less than half of the message, so, less than half of the answer is:

Pretty simple really. Just change line

Solved.

My php code at the web server end was adding quotes around the string. Removing these quotes allowed me to put the returned string directly into:

JsonObject& parsed = JSONBuffer.parseObject(returned_http_get_string); //Parse message

Thanks @PaulS