2021-07-23 12:48 PM
Hi Guys,
I run the following code in a STM32F4429ZI board (a project was generated with STMCube 6.3 and I´m using Cube IDE 1.7):
// Create a json object
cJSON *info;
info=cJSON_CreateObject();
//adding data
cJSON_AddStringToObject(info,"sex","male");
cJSON_AddNumberToObject(info,"age",20);
cJSON_AddStringToObject(info,"name","weijun");
// character pointer
char *jsonStr;
But in the jsonStr only the first two string was added. See bellow:
Name : jsonStr
Details:0x20006e90 "{\n\t\"sex\":\t\"male\",\n\t\"age\":\t"
Default:0x20006e90 "{\n\t\"sex\":\t\"male\",\n\t\"age\":\t"
Decimal:536899216
Hex:0x20006e90
Binary:100000000000000110111010010000
Octal:04000067220
What is wrong? I´ve just tried integrate cJSON in meu projetct today.
Geraldo.
2021-07-30 06:26 AM
Hi, my workaround was convert the number to string using sprintf and after, I used the cJSON_AddStringToObject to add the string to cJSON object.
2021-07-30 06:40 AM
cJSON uses malloc to allocate memory. Make sure your heap size is big enough
2021-07-30 07:15 AM
Thanks Majerle. I did a lot of tests. But I´ll test and check again.
Thanks.