Hi
Are there any examples of how to use JSON with nRF5340 DK (or similar) and nRF Connect?
I am using SDK v2.4.1.
I found these files:
c:\ncs\v2.4.1\nrf\ext\iperf3\cjson.c and cjson.h
I wasn't able to include them, so I just copied them to my project folder.\I had to comment out the " iperf_config.h" include in cjson.h.
I was able to write some basic code:
cJSON *json_obj;
cJSON *json_item;
bool b_result;
const char *key_str = "key_1";
char *val_str = "value_1";
char *json_str = NULL;
// Create empty JSON object
json_obj = cJSON_CreateObject();
// Create a JSON item
json_item = cJSON_CreateString(val_str);
// Add an item to this object
b_result = cJSON_AddItemToObject(json_obj, key_str, json_item);
// Print the full string
json_str = cJSON_Print(json_obj);
// Finished with object, so delete it!
cJSON_Delete(json_obj);
Initially I got some error about CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE being 0, so in the prj.conf file I set:
CONFIG_MINIMAL_LIBC_MALLOC=y CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=1000
This builds if I comment out the call to cJSON_Print().
I can continue to work with this - although I don't understand how I would eventually "release" the json_str created by cJSON_Print() etc.
So I was hoping there was sample code out there, with the correct includes etc.