cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

Very long String not added on printed JSON

Open ricbrue opened this issue 3 years ago • 1 comments

Hi, I've an issue using this library on an ESP32 device. I've to add a very long string (char* encoded_base64_data) which is around 20000 bytes long to a JSON. almost the 75% of the times the produced JSON does not contain the string (added through cJSON_AddStringToObject(root, "data_base64", encoded_base64_data);) Which could be the reason of that? I have tried to add to the root object through the cJSON_CreateStringReference without any success.

ricbrue avatar Dec 30 '20 14:12 ricbrue

Sorry I don't have ESP32 environment, but I can't reproduce this in my linux server, this may be related with memory limitations on embedded systems or incompatibility with some built-in functions.

Could you print the valuestring directly like this: printf("data_base64: %s\n", cJSON_GetObjectItem(root, "data_base64")->valuestring);? Suggesting check whether the return value is NULL when adding item to object through cJSON_AddStringToObject, so that we could make sure whether the item is successfully added.

Alanscut avatar Dec 31 '20 04:12 Alanscut