cJSON
cJSON copied to clipboard
Very long String not added on printed JSON
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.
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.