update to pika_cjson to package

This commit is contained in:
pikastech 2022-06-06 14:55:57 +08:00
parent 349422afe3
commit 18c3c70d8b
3 changed files with 17 additions and 13 deletions

View File

@ -12,7 +12,6 @@ class cJSON(TinyObj):
cJSON_Object: int
cJSON_Raw: int
def print(self) -> str: ...
def parse(self, value: str): ...
def __del__(self): ...
def __init__(self): ...
def getObjectItem(self, string: str) -> cJSON: ...
@ -41,6 +40,10 @@ class cJSON(TinyObj):
def addItemToObject(self, string: str, item: cJSON): ...
class Parse(cJSON):
def __init__(self, value: str): ...
class Null(cJSON):
def __init__(self): ...

View File

@ -1,17 +1,6 @@
#include "pika_cjson_cJSON.h"
#include "cJSON.h"
void pika_cjson_cJSON_parse(PikaObj* self, char* value) {
cJSON* item = cJSON_Parse(value);
if (NULL == item) {
obj_setErrorCode(self, 3);
__platform_printf("Error: cJSON parse faild.\r\n");
return;
}
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);

View File

@ -7,6 +7,7 @@
#include "pika_cjson_Number.h"
#include "pika_cjson_Object.h"
#include "pika_cjson_ObjectReference.h"
#include "pika_cjson_Parse.h"
#include "pika_cjson_Raw.h"
#include "pika_cjson_String.h"
#include "pika_cjson_StringReference.h"
@ -97,4 +98,15 @@ void pika_cjson_ArrayReference___init__(PikaObj* self, PikaObj* child) {
cJSON* item = cJSON_CreateArrayReference(child_item);
obj_setPtr(self, "item", item);
obj_setInt(self, "needfree", 1);
}
}
void pika_cjson_Parse___init__(PikaObj* self, char* value) {
cJSON* item = cJSON_Parse(value);
if (NULL == item) {
obj_setErrorCode(self, 3);
__platform_printf("Error: cJSON parse faild.\r\n");
return;
}
obj_setPtr(self, "item", item);
obj_setInt(self, "needfree", 1);
}