#include <json-c/json.h>
#include <stdio.h>
#include <unistd.h>
#include <mcheck.h>
int main()
{
setenv("MALLOC_TRACE", "output_file_name", 1);
mtrace();
struct json_object *Object = json_object_new_object();
struct json_object *CpObject = json_object_new_object();
struct json_object *CpArray = json_object_new_array();
json_object_object_add(Object, "Time", json_object_new_string("yyyy_mm_dd"));
json_object_object_add(Object, "Name", json_object_new_string("123"));
json_object_object_add(Object, "Action", json_object_new_string("456"));
json_object_object_add(CpObject, "Code", json_object_new_string("11"));
json_object_object_add(CpObject, "Type", json_object_new_string("22"));
json_object_object_add(CpObject, "SubType", json_object_new_string("33"));
json_object_array_add(CpArray, CpObject);
json_object_object_add(Object, "CpCommands", CpArray);
printf ("%s\n",json_object_to_json_string(Object));
//free memory
json_object_put(Object);
json_object_put(CpObject);
}
Hi,In below example, i see both json_object_put is called for both Object and CpObject.Is that fine? Can we avoid calling json_object_put for CpObject?regards,
Sriram I...
struct json_object *Object = json_object_new_object();
struct json_object *CpObject = json_object_new_object();
struct json_object *CpArray = json_object_new_array();
...