diff --git a/inc/cson_interface.h b/inc/cson_interface.h index 3465caf..fe4b14d 100644 --- a/inc/cson_interface.h +++ b/inc/cson_interface.h @@ -14,6 +14,8 @@ * to use, or define other parser which conforms to this interface. * */ +#include "stddef.h" + /** * @brief the type of json object. */ diff --git a/src/cson_packer.c b/src/cson_packer.c index 42066c5..a16adb4 100644 --- a/src/cson_packer.c +++ b/src/cson_packer.c @@ -144,11 +144,12 @@ int getJsonArray(void* input, const reflect_item_t* tbl, int index, cson_t* obj) size_t successCount = 0; for (int i = 0; i < size; i++) { - cson_t jotmp = cson_object(); + cson_t jotmp; if(tbl[index].reflect_tbl[0].field[0] == '0'){ /* field start with '0' mean basic types. */ ret = jsonPackTbl[tbl[index].reflect_tbl[0].type](pSrc + (i * tbl[index].arraySize), tbl[index].reflect_tbl, 0, &jotmp); - }else{ + }else{ + jotmp = cson_object(); ret = csonStruct2JsonObj(jotmp, pSrc + (i * tbl[index].arraySize), tbl[index].reflect_tbl); } @@ -156,6 +157,7 @@ int getJsonArray(void* input, const reflect_item_t* tbl, int index, cson_t* obj) successCount++; cson_array_add(joArray, jotmp); } else { + printf("create array item faild.\n"); cson_decref(jotmp); } }