2020-02-05 12:16:15 +08:00
|
|
|
#include "cson.h"
|
|
|
|
#include "stdio.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char* name;
|
|
|
|
char* jump_url;
|
2020-02-25 17:38:54 +08:00
|
|
|
} ClassInfoChild;
|
2020-02-05 12:16:15 +08:00
|
|
|
|
|
|
|
typedef struct {
|
2020-02-25 17:38:54 +08:00
|
|
|
int has_child;
|
|
|
|
char* icon;
|
|
|
|
int id;
|
|
|
|
char* name;
|
|
|
|
char childrenNum;
|
2020-02-05 12:16:15 +08:00
|
|
|
ClassInfoChild* children;
|
2020-02-25 17:38:54 +08:00
|
|
|
} ClassInfo;
|
2020-02-05 12:16:15 +08:00
|
|
|
|
|
|
|
typedef struct {
|
2020-02-25 17:38:54 +08:00
|
|
|
long long timestamp;
|
2020-03-12 21:37:45 +08:00
|
|
|
int infoNum;
|
2020-02-25 17:38:54 +08:00
|
|
|
ClassInfo* info;
|
|
|
|
} Data;
|
2020-02-05 12:16:15 +08:00
|
|
|
|
|
|
|
typedef struct {
|
2020-02-25 17:38:54 +08:00
|
|
|
int status;
|
|
|
|
Data data;
|
|
|
|
int errcode;
|
|
|
|
} Response;
|
2020-02-05 12:16:15 +08:00
|
|
|
|
2020-02-25 17:38:54 +08:00
|
|
|
reflect_item_t ClassInfoChildTbl[] = {
|
2020-02-05 12:16:15 +08:00
|
|
|
_property_string(ClassInfoChild, name),
|
|
|
|
_property_string(ClassInfoChild, jump_url),
|
|
|
|
_property_end()
|
|
|
|
};
|
|
|
|
|
2020-02-25 17:38:54 +08:00
|
|
|
reflect_item_t ClassInfoTbl[] = {
|
2020-02-05 12:16:15 +08:00
|
|
|
_property_int(ClassInfo, has_child),
|
|
|
|
_property_string(ClassInfo, icon),
|
|
|
|
_property_int(ClassInfo, id),
|
|
|
|
_property_string(ClassInfo, name),
|
|
|
|
_property_int(ClassInfo, childrenNum),
|
|
|
|
_property_array_object(ClassInfo, children, ClassInfoChildTbl, ClassInfoChild, childrenNum),
|
|
|
|
_property_end()
|
|
|
|
};
|
|
|
|
|
2020-02-25 17:38:54 +08:00
|
|
|
reflect_item_t DataTbl[] = {
|
2020-02-05 12:16:15 +08:00
|
|
|
_property_int(Data, timestamp),
|
|
|
|
_property_int(Data, infoNum),
|
|
|
|
_property_array_object(Data, info, ClassInfoTbl, ClassInfo, infoNum),
|
|
|
|
_property_end()
|
|
|
|
};
|
|
|
|
|
2020-02-25 17:38:54 +08:00
|
|
|
reflect_item_t ResponseTbl[] = {
|
2020-02-05 12:16:15 +08:00
|
|
|
_property_int(Response, status),
|
2020-02-25 17:38:54 +08:00
|
|
|
_property_obj(Response, data, DataTbl),
|
2020-02-05 12:16:15 +08:00
|
|
|
_property_int(Response, errcode),
|
|
|
|
_property_end()
|
|
|
|
};
|
|
|
|
|
|
|
|
//const static char* jStr = "{\"status\":1,\"error\":\"\",\"data\":{\"timestamp\":1579058755,\"info\":[{\"has_child\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181130/20181130172345416784.png\",\"id\":32,\"name\":\"年代\",\"subtitle\":\"\",\"description\":\"\"},{\"has_child\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181130/20181130172408696210.png\",\"id\":58,\"name\":\"乐器\",\"subtitle\":\"\",\"description\":\"\"}]},\"errcode\":0}";
|
|
|
|
|
|
|
|
//const static char* jStr = "{\"status\":1,\"error\":\"\",\"data\":{\"timestamp\":1579058755,\"info\":[{\"has_child\":1,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181130/20181130172444711866.png\",\"id\":153,\"children\":[{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F1\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20190402/20190402165900910180.png\",\"id\":185,\"name\":\"DJ专区\",\"special_tag_id\":0,\"bannerurl\":\"http://imge.kugou.com/v2/mobile_class_banner/{size}/T1hFCsBvW_1RCvBVdK.png\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"http://imge.kugou.com/mcommon/{size}/20150825/20150825145251513968.png\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F45\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20190711/20190711142859901220.png\",\"id\":1401,\"name\":\"抖音专区\",\"special_tag_id\":0,\"bannerurl\":\"\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F15\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181106/20181106162159569853.png\",\"id\":155,\"name\":\"影视专区\",\"special_tag_id\":0,\"bannerurl\":\"http://imge.kugou.com/v2/mobile_class_banner/{size}/T1xzKsBvWT1RCvBVdK.png\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"http://imge.kugou.com/mcommon/{size}/20150916/20150916115630236448.png\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F25\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181101/20181101110659435688.png\",\"id\":803,\"name\":\"戏曲专区\",\"special_tag_id\":0,\"bannerurl\":\"\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F13\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181106/20181106162128954559.png\",\"id\":625,\"name\":\"粤剧专区\",\"special_tag_id\":0,\"bannerurl\":\"\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F31\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20191115/20191115142149416417.png\",\"id\":1031,\"name\":\"韩流专区\",\"special_tag_id\":0,\"bannerurl\":\"\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"}],\"name\":\"专区\",\"subtitle\":\"\",\"description\":\"\"},{\"has_child\":1,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20191104/20191104103209217784.png\",\"id\":2005,\"children\":[{\"jump_url\":\"\",\"album_tag_id\":0,\"icon\":\"\",\"id\":2167,\"name\":\"开心专区\",\"special_tag_id\":0,\"bannerurl\":\"\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"\",\"banner_hd\":\"http://imge.kugou.com/mcommon/{size}/20191112/20191112114657687089.jpg\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"\",\"album_tag_id\":0,\"icon\":\"\",\"id\":2173,\"name\":\"想念专区\",\"special_tag_id\":0,\"bannerurl\":\"\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"\",\"banner_hd\":\"http://imge.kugou.com/mcommon/{size}/20191112/20191112141710521727.jpg\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"\",\"album_tag_id\":0,\"icon\":\"\",\"id\":2179,\"name\":\"疗伤专区\"
|
|
|
|
|
|
|
|
const static char* jStr = "{\"status\":1,\"error\":\"\",\"data\":{\"timestamp\":1579069151,\"info\":[{\"has_child\":1,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181130/20181130172444711866.png\",\"id\":153,\"children\":[{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F1\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20190402/20190402165900910180.png\",\"id\":185,\"name\":\"DJ专区\",\"special_tag_id\":0,\"bannerurl\":\"http://imge.kugou.com/v2/mobile_class_banner/{size}/T1hFCsBvW_1RCvBVdK.png\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"http://imge.kugou.com/mcommon/{size}/20150825/20150825145251513968.png\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F45\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20190711/20190711142859901220.png\",\"id\":1401,\"name\":\"抖音专区\",\"special_tag_id\":0,\"bannerurl\":\"\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F3\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20190402/20190402165839822861.png\",\"id\":227,\"name\":\"儿童专区\",\"special_tag_id\":0,\"bannerurl\":\"http://imge.kugou.com/v2/mobile_class_banner/{size}/T1xNKsBmb_1RCvBVdK.png\",\"song_tag_id\":0,\"is_hot\":1,\"imgurl\":\"http://imge.kugou.com/mcommon/{size}/20150819/20150819142111579284.png\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F23\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181101/20181101110341142930.png\",\"id\":781,\"name\":\"网络专区\",\"special_tag_id\":0,\"bannerurl\":\"\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F9\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181101/20181101110304370142.png\",\"id\":405,\"name\":\"车载专区\",\"special_tag_id\":0,\"bannerurl\":\"http://imge.kugou.com/v2/mobile_class_banner/{size}/T1TJKsB_K_1RCvBVdK.png\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"http://imge.kugou.com/mcommon/{size}/20151020/20151020185634232826.png\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F11\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181101/20181101110531714649.png\",\"id\":483,\"name\":\"广场舞专区\",\"special_tag_id\":0,\"bannerurl\":\"http://imge.kugou.com/v2/mobile_class_banner/{size}/T13ebsBgC_1RCvBVdK.png\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"http://imge.kugou.com/mcommon/{size}/20151030/20151030100347338896.png\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F17\",\"album_tag_id\":0,\"icon\":\"http://imge.kugou.com/mcommon/{size}/20181101/20181101110434661130.png\",\"id\":439,\"name\":\"轻音乐专区\",\"special_tag_id\":0,\"bannerurl\":\"http://imge.kugou.com/v2/mobile_class_banner/{size}/T1jTJsBmZT1RCvBVdK.png\",\"song_tag_id\":0,\"is_hot\":0,\"imgurl\":\"http://imge.kugou.com/mcommon/{size}/20151026/20151026102137944162.png\",\"banner_hd\":\"\",\"is_new\":0,\"has_child\":1,\"theme\":1,\"subtitle\":\"\",\"description\":\"\"},{\"jump_url\":\"https://miniapp.kugou.com/node/v2?type=1&id=74&path=%2Findex.html%23%2Fmobile%2Fhome%2F
|
|
|
|
|
2020-02-25 17:38:54 +08:00
|
|
|
void test2()
|
|
|
|
{
|
|
|
|
printf("=========================================\n");
|
2020-02-05 12:16:15 +08:00
|
|
|
printf("\t\tRunning %s\n", __FUNCTION__);
|
|
|
|
printf("=========================================\n");
|
|
|
|
Response resp;
|
|
|
|
|
|
|
|
/* string to struct */
|
|
|
|
int ret = csonJsonStr2Struct(jStr, &resp, ResponseTbl);
|
|
|
|
/* test print */
|
|
|
|
printf("ret=%d\n", ret);
|
2020-03-12 21:37:45 +08:00
|
|
|
csonPrintProperty(&resp, ResponseTbl);
|
2020-02-05 12:16:15 +08:00
|
|
|
|
|
|
|
char* jstrOutput;
|
|
|
|
ret = csonStruct2JsonStr(&jstrOutput, &resp, ResponseTbl);
|
|
|
|
printf("ret=%d\nJson:%s\n", ret, jstrOutput);
|
|
|
|
free(jstrOutput);
|
2020-03-12 21:37:45 +08:00
|
|
|
csonFreePointer(&resp, ResponseTbl);
|
2020-02-05 12:16:15 +08:00
|
|
|
}
|