pikapython/package/pika_cjson/cJSON_cJSON.c
2022-06-02 17:47:53 +08:00

39 lines
1.0 KiB
C

#include "pika_cjson_cJSON.h"
#include "cJSON.h"
void pika_cjson_cJSON_parse(PikaObj* self, char* value) {
cJSON* item = cJSON_Parse(value);
obj_setPtr(self, "item", item);
obj_setInt(self, "needfree", 1);
}
char* pika_cjson_cJSON_print(PikaObj* self) {
cJSON* item = obj_getPtr(self, "item");
char* res = cJSON_Print(item);
obj_setStr(self, "_buf", res);
cJSON_free(res);
return obj_getStr(self, "_buf");
}
void pika_cjson_cJSON___del__(PikaObj* self) {
cJSON* item = obj_getPtr(self, "item");
if (obj_getInt(self, "needfree") == 1) {
cJSON_Delete(item);
}
}
Arg* pika_cjson_cJSON_getObjectItem(PikaObj* self, char* string) {
cJSON* item = obj_getPtr(self, "item");
cJSON* subItem = cJSON_GetObjectItem(item, string);
/* create subCJSON */
Arg* subCJSON_arg = obj_newObjInPackage(New_pika_cjson_cJSON);
/* init the subCJSON */
PikaObj* subCJSON = arg_getPtr(subCJSON_arg);
obj_setPtr(subCJSON, "item", subItem);
obj_setInt(subCJSON, "needfree", 0);
return subCJSON_arg;
}