百度站长平台网页版,seo网站搭建,wordpress版本更新,怎么把网站做火(1)使用root cJSON_Parse(text);
//将字符串转成json格式#xff0c;函数中申请了一块内存给root 所以在最后要释放root
cJSON_Delete(root ); //释放cJSON_Parse()分配出来的内存空间
(2)使用out cJSON_Print(root);#xff08;含有cJSON_PrintUnformatted函数#x…(1)使用root cJSON_Parse(text);
//将字符串转成json格式函数中申请了一块内存给root 所以在最后要释放root
cJSON_Delete(root ); //释放cJSON_Parse()分配出来的内存空间
(2)使用out cJSON_Print(root);含有cJSON_PrintUnformatted函数
//函数将json数据转成字符串这个函数内申请了一段内存给out所以使用完out后也要释放
由于out不是json指针的数据格式使用cJSON_free(out);释放即可
(3使用cJSON new_json_str cJSON_Create*(str);
//将一个字符串转成一个json对象函数里面也涉及了内存分配用完以后也要释放cJSON_Delete(new_json_str );
若cJSON new_json cJSON_Create*(str)创建后通过cJSON_AddItemToObject( json, test, new_json );或者cJSON_AddItemToArray加入到数组或者object中不需要单独释放new_json 删除json时被添加的item此处为申请的new_json同时也会被删除。
注意cJSON_Delete( ) ,cJSON_free ( ) 要区分使用json格式的使用cJSON_Delete 指针格式使用cJSON_free对应关系如下
申请内存 cJSON_Parse cJSON_Create cJSON_Print 释放内存 cJSON_Delete cJSON_Delete cJSON_free Referenced from:cjson内存泄漏问题注意事项-CSDN博客