I'm able to get json data and storing in String object, now i want to convert string into Char Array for parsing json data

I'm tried with this code, but it is not responding

      String data = http.getString();   //Get the request response payload
      Serial.println(data);                     //Print the response payload
      int len=data.length();

      char  buf[len + 1];
      data.toCharArray(buf, len + 1);        
      int bufLength = sizeof(buf);
      Serial.println(bufLength);   //Printing nothing
  • 2
    Tried c_str()? – Edgar Bonet Dec 23 '17 at 18:27
  • No, can you tell me how it converts String JSON data to char Array – Anne Lingesh Dec 23 '17 at 18:31
  • 1) Your code does work when I try it: all the Serial.println() do print their stuff. 2) It converts the String to a char array by giving you “direct access to the internal String buffer”. It's written in the doc I linked to. – Edgar Bonet Dec 23 '17 at 18:39
  • for me, it is printing like this Exception (9): epc1=0x40203d9e epc2=0x00000000 epc3=0x00000000 excvaddr=0x64522072 depc=0x00000000 after len – Anne Lingesh Dec 23 '17 at 18:47
  • There is no need for char array. It's possible to access elements inside of String by data[index]. Or you can use ArduinoJson library – KIIV Dec 23 '17 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.