I've a json string request coming from server and I convert it into json object

  StaticJsonBuffer<500> jsonStaticBuffer;
  JsonObject& root = jsonStaticBuffer.parseObject(String(msg));
  String reqId;
  String reqData;

I need to populate another char json string initiated at the beginning

const char response[] = "{\"response\": {\"requestid\":, \"data\":}}"; 

such that I need to write requestid into the response::requestid and data into response::data + ACK/NAK . here is how i've tried;

  DynamicJsonBuffer jsonDynResponse; 
  JsonObject& jsonResponse = jsonDynResponse.parseObject(response);   
  String out;  
  if (ACK) {
      jsonResponse["response"]["requestid"] = root["requestid"]; 
      jsonResponse["response"]["data"] = root["data"] + " ACK"; //THIS DOESN'T WORKS
  } else {
      jsonResponse["response"]["requestid"] = reqId;
      jsonResponse["response"]["data"] = reqData + " NAK";  

I know this will definitely not work root["data"] + " ACK" because we can't combine const char with String. But this reqData + " NAK"; resulted in "\"data\" NAK"". How can I concate root["data"] into another String ? Thank you in advance :)

  • String(root["data"]) + " ACK"? – Jaromanda X Jan 9 at 5:37
  • Tried that already, I get exit status 1 call of overloaded 'String(ArduinoJson::Internals::JsonObjectSubscript<const char*>)' is ambiguous – Anum Sheraz Jan 9 at 9:46
  • perhaps you need to create a String variable, do things with it, and then jsonResponse["response"]["data"] = whateverYourStringVariableIsCalled; – Jaromanda X Jan 9 at 9:52
  • The things that I want to do with the string is append ACK/NAK on whatever is in root["data"]. Which I am not able to do. – Anum Sheraz Jan 9 at 15:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.