Home > other >  CJSON is empty after using cJSON_AddNumberToObject add value?
CJSON is empty after using cJSON_AddNumberToObject add value?

Time:12-03

On esp8266, use cjson data formats, encapsulation json, failure detection using cJSON_AddNumberToObject add a numeric type, print data after encapsulation, empty, add the string types can be again, on a Windows platform with vs2015 tested cjson, also is no problem, occurs in esp8266 key corresponding value is empty, code printing results, as shown in the figure shown below
 cJSON * root=NULL; 
Char * out=NULL;
Root=cJSON_CreateObject ();
If (NULL==root) printf (" cJSON_CreateObject err \ n ");
CJSON_AddNumberToObject (root, "type", 2);
CJSON_AddNumberToObject (root, "errorCode", code);
CJSON_AddStringToObject (root, "STR", "STR");

Out=cJSON_Print (root);
If (NULL==out) printf (" cJSON_Print err ");
CJSON_Delete (root);

SendToUart ((unsigned char *) out, strlen (out));
Send: printf (" % s \ n ", out);
Free (out);




CodePudding user response:

CJson libraries may not achieve cJSON_AddNumberToObject (source code is not found in the function), you can first

CJSON * cJSON_CreateNumber (double num) data object, then the
cJSON_AddItemToObjec

CodePudding user response:

Thank you for your reply, although the problem not solve, I tried, is also not
  • Related