2

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();
      Serial.println(len);  

      char  buf[len + 1];
      data.toCharArray(buf, len + 1);        
      int bufLength = sizeof(buf);
      Serial.println(bufLength);   //Printing nothing
6
  • 2
    Tried c_str()? Dec 23, 2017 at 18:27
  • No, can you tell me how it converts String JSON data to char Array Dec 23, 2017 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. Dec 23, 2017 at 18:39
  • for me, it is printing like this Exception (9): epc1=0x40203d9e epc2=0x00000000 epc3=0x00000000 excvaddr=0x64522072 depc=0x00000000 after len Dec 23, 2017 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, 2017 at 23:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.