This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

JSON object creating problem

Hello 

i am using cJSON keil library but i facing many problem to create object and convert object into string.

1. This code work fine

 int main(void)
{

 root = cJSON_CreateObject();

cJSON_AddNumberToObject(root, "w", 1920);
cJSON_AddNumberToObject(root, "h", 1080);


//cJSON_AddNumberToObject(root, "f", 24); // This line is commented


cJSON_AddBoolToObject (root, "i",1);

char *string = cJSON_Print(root);

while (1)
{

HAL_UART_Transmit(&huart3,(uint8_t *)string , strlen(string),HAL_MAX_DELAY);

HAL_Delay(500);

}

the above code work fine but when i uncomment  the commented line (cJSON_AddNumberToObject(root, "f", 24);) , after that i did't get any value in string, i found null in string.

and also when i create two object than also i got null in both object's strings.

Can any please tell me why i am facing these problems. 

Parents
  • Check if you have enough heap defined.

    You can also debug the cJSON functions to find out where the problem is.

    I have quickly tried the above code (without the HAL  - just looked at the string) and I see the expected string also when enabling the line which ads number "f".

    {
      "w":  1920,
      "h":  1080,
      "f":  24,
      "i":  true
    }

Reply
  • Check if you have enough heap defined.

    You can also debug the cJSON functions to find out where the problem is.

    I have quickly tried the above code (without the HAL  - just looked at the string) and I see the expected string also when enabling the line which ads number "f".

    {
      "w":  1920,
      "h":  1080,
      "f":  24,
      "i":  true
    }

Children
No data