bianbian coding life

便便代码人生: 关注技术, 翻译文档, 偶尔动动手

[原] 根据struct生成基于JSON-C的json_object代码(auto generate function of C struct to JSON)

Posted by bianbian on 2008-04-09 11:13

本文Tags: ,

上次讨论了C的struct结构体与JSON交互,并提出了能否自动把struct转为JSON的问题。
今天我总算解决了这个问题,虽然中间也想过传参数给一个函数集中处理,不过都是比较麻烦。我写了一个脚本,自动生成把struct的成员插入json_object的函数,底下页面有演示:auto generate function of C struct to JSON

标签: ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

4 Responses to “[原] 根据struct生成基于JSON-C的json_object代码(auto generate function of C struct to JSON)”

  1. Sunshow Says:

    编码原因吗
    我这不好使
    还乱码

  2. Govan Hooper Says:

    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

  3. bianbian Says:

    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.

  4. » [原] C#泛型实现流中C/C++格式的struct数据的通用读取方法 » Technology » bianbian coding life Says:

    […] 我观察了一下,倒是可以考虑写个脚本自动切换。类似以前写的根据struct生成基于JSON-C的json_object代码 标签: C#, Marshal, struct, […]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

(required)