jasson库使用注意

2019-04-16  本文已影响0人  梦落迹南天
  1. json_decref()
    释放创建的object的引用,一些获取json_object返回的是new reference 需要手动进行释放:
json_t *json_object(void)¶
Return value: New reference.
Returns a new JSON object, or NULL on error. Initially, the object is empty.

但是有些函数返回的时候borrow reference :

json_t *json_object_get(const json_t *object, const char *key)¶
Return value: Borrowed reference.
Get a value corresponding to key from object. Returns NULL if key is not found and on error.

这是没有计入引用的使用,最好手动去json_incref(),然后手动json_decref()释放

上一篇 下一篇

猜你喜欢

热点阅读