Tag: json c

如何清理“json_object_new_string”创建的json对象?

我有以下代码,我想清理由json_object_new_string()创建的json对象。 #include #include int main() { /*Creating a json object*/ json_object * jobj = json_object_new_object(); /*Creating a json string*/ json_object *jstring = json_object_new_string(“Joys of Programming”); /*Form the json object*/ json_object_object_add(jobj,”Site Name”, jstring); /*Now printing the json object*/ printf (“The json object created: %sn”,json_object_to_json_string(jobj)); /* clean the json object */ json_object_put(jobj); } 行json_object_put(jobj); 清理jobj和jstring ? 或者我必须使用json_object_put(jstring);单独使用干净的jstring […]

内存泄漏使用JSON-C

我是JSON-C的新手,请查看我的示例代码,让我知道它会创建任何内存泄漏,如果是,那么如何释放JSON-C对象。 struct json_object *new_obj = NULL; new_obj = json_tokener_parse(strRawJSON); new_obj = json_object_object_get(new_obj, “FUU”); if(NULL == new_obj){ SYS_OUT(“\nFUU not found in JSON”); return NO; } new_obj = json_object_object_get(new_obj, “FOO”); // I m re-using new_obj, without free it? if(NULL == new_obj){ SYS_OUT(“\nFOO not found in JSON”); return NO; } // DO I need to clean new_obj, if […]