diff --git a/readme.md b/readme.md index 1845cee..72ccc49 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # CSON -![version](https://img.shields.io/badge/version-1.0.0-brightgreen.svg) -![build](https://img.shields.io/badge/build-2019.8.27-brightgreen.svg) +![version](https://img.shields.io/badge/version-1.0.1-brightgreen.svg) +![build](https://img.shields.io/badge/build-2019.9.4-brightgreen.svg) 基于[cJSON](https://github.com/kbranigan/cJSON),运行于C语言平台的json-struct模型解析工具 diff --git a/src/cson.c b/src/cson.c index 5771639..9399334 100644 --- a/src/cson.c +++ b/src/cson.c @@ -245,6 +245,10 @@ void *csonDecodeObject(cJSON *json, CsonModel *model, int modelSize) { CSON_ASSERT(json, return NULL); + if (json->type == cJSON_NULL) { + return NULL; + } + short objSize = 0; for (short i = 0; i < modelSize; i++) { @@ -452,7 +456,9 @@ cJSON* csonEncodeArray(void *base, CsonType elementType, short arraySize) */ cJSON* csonEncodeObject(void *obj, CsonModel *model, int modelSize) { - CSON_ASSERT(obj, return NULL); + if (!obj) { + return cJSON_CreateNull(); + } cJSON *root = cJSON_CreateObject(); for (short i = 0; i < modelSize; i++) @@ -461,7 +467,6 @@ cJSON* csonEncodeObject(void *obj, CsonModel *model, int modelSize) { case CSON_TYPE_CHAR: csonEncodeNumber(root, model[i].key, *(char *)((int)obj + model[i].offset)); - // cJSON_AddNumberToObject(root, model[i].key, *(char *)((int)obj + model[i].offset)); break; case CSON_TYPE_SHORT: csonEncodeNumber(root, model[i].key, *(short *)((int)obj + model[i].offset)); @@ -483,7 +488,6 @@ cJSON* csonEncodeObject(void *obj, CsonModel *model, int modelSize) break; case CSON_TYPE_STRING: csonEncodeString(root, model[i].key, (char *)(*(int *)((int)obj + model[i].offset))); - // cJSON_AddStringToObject(root, model[i].key, (char *)(*(int *)((int)obj + model[i].offset))); break; case CSON_TYPE_LIST: cJSON_AddItemToObject(root, model[i].key, diff --git a/src/cson.h b/src/cson.h index ccedb28..79cfdd6 100644 --- a/src/cson.h +++ b/src/cson.h @@ -16,7 +16,7 @@ #include "cJSON.h" -#define CSON_VERSION "1.0.0" /**< CSON版本 */ +#define CSON_VERSION "1.0.1" /**< CSON版本 */ /** * @defgroup CSON cson