[原] 根据struct生成基于JSON-C的json_object代码(auto generate function of C struct to JSON)
Posted by bianbian on 2008-04-09 11:13
上次讨论了C的struct结构体与JSON交互,并提出了能否自动把struct转为JSON的问题。
今天我总算解决了这个问题,虽然中间也想过传参数给一个函数集中处理,不过都是比较麻烦。我写了一个脚本,自动生成把struct的成员插入json_object的函数,底下页面有演示:auto generate function of C struct to JSON:
遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道
April 9th, 2008 at 12:13:36
编码原因吗
我这不好使
还乱码
June 23rd, 2008 at 12:56:42
Sooooooooo cooooooooool
But how to convert a C struct which include pointer field point to a struct ?
For example:
struct LOCK_IP {
char ip[20]; //lock ip
int time; //lock time
float a; //just e.g.
double b;
char c;
unsigned char d;
unsigned int e;
struct LOCK_IP* next;
struct someObj* obj;
};
Shall I define the function json_object_new_undefined() by myself ?
Thanks
June 24th, 2008 at 09:43:12
pointer … I think there is no simple way to handle this. Because the pointer is only the address in memory, maybe it needs more functions.
March 2nd, 2009 at 09:27:34
[…] 我观察了一下,倒是可以考虑写个脚本自动切换。类似以前写的根据struct生成基于JSON-C的json_object代码 标签: C#, Marshal, struct, […]