Missing line in cJSON

Luiz.Picolo
Posts: 7
Joined: Wed Jun 05, 2019 9:04 pm

Missing line in cJSON

Postby Luiz.Picolo » Mon Jun 24, 2019 6:16 pm

I'm converting an image to base 64 and every time I try to print in json, the json line simply disappears.

Convert image code
  1. camera_fb_t *pic = NULL;
  2.   pic = esp_camera_fb_get();
  3.  
  4.   size_t output_length; // note *NOT* a pointer
  5.   unsigned char *encoded= base64_encode((const unsigned char *)pic->buf, pic->len, &output_length);
  6.  
  7.   esp_camera_fb_return(pic);
Json code
  1.   cJSON *root = NULL;
  2.   cJSON *size = create_point(800,600);
  3.  
  4.     root = cJSON_CreateObject();
  5.     cJSON_AddStringToObject(root, "img", (const char*)encoded);
  6.     cJSON_AddItemToObject(root, "size", size);
  7.     cJSON_AddStringToObject(root, "storeId", "upload_validation_store");
  8.     cJSON_AddStringToObject(root, "clientId", "upload_validation_client");
  9.     cJSON_AddStringToObject(root, "deviceId", "1234");
  10.     cJSON_AddNumberToObject(root, "timestamp", 123456);
  11.  
  12.     if (print_preallocated(root) != 0) {
  13.     cJSON_Delete(root);
  14.     exit(EXIT_FAILURE);
  15.     }
  16.     cJSON_Delete(root);
The result:
{
"size": [800, 600],
"storeId": "upload_validation_store",
"clientId": "upload_validation_client",
"deviceId": "1234",
"timestamp": 123456
}

The img line simply disappears
Last edited by Luiz.Picolo on Mon Jul 01, 2019 7:12 pm, edited 4 times in total.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Missing line in cJSON

Postby WiFive » Mon Jun 24, 2019 8:54 pm

Is encoded null terminated and do you have enough free memory for it and does cjson support giant strings?

Luiz.Picolo
Posts: 7
Joined: Wed Jun 05, 2019 9:04 pm

Re: Missing line in cJSON

Postby Luiz.Picolo » Wed Jun 26, 2019 4:28 pm

I ended up updating the first post because of some changes in the programming, now I need to see how to put an unsigned char* in json

Luiz.Picolo
Posts: 7
Joined: Wed Jun 05, 2019 9:04 pm

Re: Missing line in cJSON

Postby Luiz.Picolo » Thu Jul 04, 2019 3:42 pm

I discovered that there is no limitation on cjson, and I have enough memory, but I could not figure out if encoded null terminated or not.
How can I do this?

Who is online

Users browsing this forum: No registered users and 112 guests