2022-06-02 17:47:53 +08:00
|
|
|
#include "pika_cjson_cJSON.h"
|
2022-06-02 16:50:31 +08:00
|
|
|
#include "cJSON.h"
|
2022-06-02 12:07:24 +08:00
|
|
|
|
2022-06-02 17:47:53 +08:00
|
|
|
void pika_cjson_cJSON_parse(PikaObj* self, char* value) {
|
2022-06-02 16:50:31 +08:00
|
|
|
cJSON* item = cJSON_Parse(value);
|
|
|
|
obj_setPtr(self, "item", item);
|
2022-06-02 17:22:14 +08:00
|
|
|
obj_setInt(self, "needfree", 1);
|
2022-06-02 14:26:57 +08:00
|
|
|
}
|
2022-06-02 16:50:31 +08:00
|
|
|
|
2022-06-02 17:47:53 +08:00
|
|
|
char* pika_cjson_cJSON_print(PikaObj* self) {
|
2022-06-02 16:50:31 +08:00
|
|
|
cJSON* item = obj_getPtr(self, "item");
|
|
|
|
char* res = cJSON_Print(item);
|
|
|
|
obj_setStr(self, "_buf", res);
|
|
|
|
cJSON_free(res);
|
|
|
|
return obj_getStr(self, "_buf");
|
|
|
|
}
|
|
|
|
|
2022-06-02 17:47:53 +08:00
|
|
|
void pika_cjson_cJSON___del__(PikaObj* self) {
|
2022-06-02 16:50:31 +08:00
|
|
|
cJSON* item = obj_getPtr(self, "item");
|
2022-06-02 17:22:14 +08:00
|
|
|
if (obj_getInt(self, "needfree") == 1) {
|
2022-06-02 16:50:31 +08:00
|
|
|
cJSON_Delete(item);
|
|
|
|
}
|
2022-06-02 17:22:14 +08:00
|
|
|
}
|
|
|
|
|
2022-06-02 17:47:53 +08:00
|
|
|
Arg* pika_cjson_cJSON_getObjectItem(PikaObj* self, char* string) {
|
2022-06-02 17:22:14 +08:00
|
|
|
cJSON* item = obj_getPtr(self, "item");
|
|
|
|
cJSON* subItem = cJSON_GetObjectItem(item, string);
|
2022-06-02 17:24:11 +08:00
|
|
|
|
|
|
|
/* create subCJSON */
|
2022-06-02 17:47:53 +08:00
|
|
|
Arg* subCJSON_arg = obj_newObjInPackage(New_pika_cjson_cJSON);
|
2022-06-02 17:24:11 +08:00
|
|
|
|
|
|
|
/* init the subCJSON */
|
|
|
|
PikaObj* subCJSON = arg_getPtr(subCJSON_arg);
|
2022-06-02 17:22:14 +08:00
|
|
|
obj_setPtr(subCJSON, "item", subItem);
|
|
|
|
obj_setInt(subCJSON, "needfree", 0);
|
2022-06-02 17:24:11 +08:00
|
|
|
|
|
|
|
return subCJSON_arg;
|
2022-06-02 17:22:14 +08:00
|
|
|
}
|