getValue is ok

This commit is contained in:
pikastech 2022-06-06 10:34:49 +08:00
parent d04b07b517
commit 788ac4acb6
2 changed files with 25 additions and 0 deletions

View File

@ -26,3 +26,4 @@ class cJSON(TinyObj):
def getValueInt(self) -> int: ...
def getValueDouble(self) -> float: ...
def getString(self) -> str: ...
def getValue(self) -> any: ...

View File

@ -116,3 +116,27 @@ char* pika_cjson_cJSON_getValueString(PikaObj* self) {
cJSON* item = obj_getPtr(self, "item");
return item->valuestring;
}
Arg* pika_cjson_cJSON_getValue(PikaObj* self) {
cJSON* item = obj_getPtr(self, "item");
int type = item->type;
if (type == cJSON_Invalid) {
return arg_setNull(NULL);
}
if (type == cJSON_False) {
return arg_setInt(NULL, "", 0);
}
if (type == cJSON_True) {
return arg_setInt(NULL, "", 1);
}
if (type == cJSON_NULL) {
return arg_setNull(NULL);
}
if (type == cJSON_Number) {
return arg_setFloat(NULL, "", item->valuedouble);
}
if (type == cJSON_String) {
return arg_setStr(NULL, "", item->valuestring);
}
return arg_setNull(NULL);
}