- 论坛徽章:
- 15
|
本帖最后由 yulihua49 于 2015-11-20 21:31 编辑
idi0t 发表于 2015-11-20 16:26 ![]()
回复 3# VIP_fuck
typedef struct person{
int32_t age;
int16_t id;
}person_stu;
配个模版:
T_PkgType person_tpl[]={
{CH_INT,sizeof(int),"age",0,-1},
{CH_SHORT,sizeof(short),"id"},
{-1,0,0,0}
};
.....
person_stu buf;
//fill value into buf;
json_object *json=json_object_new_object();
struct_to_json(json,buf,persion_tpl,NULL);// 变JSON啦
const char *cp=json_object_to_json_string(json);//序列化
100个结构需要100个模版。程序就是那几个。
模版,有自动的半自动的生成器。
见QQ SDBC,开源,自己下载使用。
|
|