1

I am using cjson library to create json and send it to server. I am using following code

char *string = cJSON_Print(json);

For which I get following output

{
  "type1": "car",
  "type2": "bus",
}

But the server expects it in string format like this

"{\n\t\"type1\":\t\"car\",\n\t\"type2\":\t\"bus\"\n}"

I am confused how can I achieve such conversion?

prattom
  • 1,625
  • 11
  • 42
  • 67
  • 1
    are you sure that what the server expects isn't the C representation of your json? or maybe there was an encoding too many... – Jean-François Fabre May 10 '19 at 08:29
  • 2
    Try `cJSON_PrintUnformatted`. "`cJSON_Print` will print with whitespace for formatting. If you want to print without formatting, use `cJSON_PrintUnformatted`." This is from cJSON read me. – Shubham May 10 '19 at 09:39
  • cJSON_Print will give you `"{\n\t\"type1\":\t\"car\",\n\t\"type2\":\t\"bus\"\n}"`. On printing it on stdout should look like the output you are actually getting. So, you have achieved it. – Shubham May 10 '19 at 09:47

0 Answers0