cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 and cJSON problem?

Geraldo Pereira
Associate II

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.

3 REPLIES 3
Geraldo Pereira
Associate II

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.

cJSON uses malloc to allocate memory. Make sure your heap size is big enough

Geraldo Pereira
Associate II

Thanks Majerle. I did a lot of tests. But I´ll test and check again.

Thanks.