c - 提取 jansson JSON 数据

标签 c json

我正在使用 C jansson 库 http://www.digip.org/jansson/

使用起来相当简单https://jansson.readthedocs.org/en/2.7/tutorial.html#the-program

但是我无法从我的 JSON 字符串中得到一个简单的 int。我可以成功接收并加载一串JSON(因为我没有收到任何错误,没有null)但是当我使用jansson get获取 int 的函数,我的 int 始终为 0,即使使用步骤和断点,jansson 函数处理 in 返回 0。

JSON 字符串如下所示:

{"type":3}

代码如下:

static void foo(json_t *jsonRoot) {
    // json root is error checked even before this, and is not null
    if (jsonRoot == NULL) {
        return;
    }

    // Trying to get type = 3
    json_t *j_type;
    int type = 0;

    j_type = json_object_get(jsonRoot, "type");
    if (!json_is_integer(j_type)) {
        printf("Not an int!\n");
        return;
    } else {
        // I get in to the else
        // json_integer_value has a its own internal check and 
        // will return 0 if the value is not an int, but it is not 
        // returning 0. It is running the macro json_to_integer(json)->value
        type = json_integer_value(j_type);
    }

    printf("type is %d\n", type);
    // type is 0
}

最佳答案

我的问题是 strtoll。我不得不重新定义它。

关于c - 提取 jansson JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35807391/

相关文章:

C 不从文件加载信息(fread、fwrite)

java - http (json) 库,客户端和服务器,可能是异步的

javascript - Zendesk 更新票及多条评论

ios - 在 NSURLSession POST 请求后快速重新加载数据的时间是多少

ios - ionic 下拉IOS

php - 如何从Android应用程序的mysql数据库中检索数据

c - 为什么在 C 中将 argv(参数 vector )定义为指针,以及将其第零定义为程序名称的需要是什么?

使用 getopt() : giving command line flags criteria 进行 C 编程

C: snprintf 不接受 GUI 显示。需要建议

C99:复数的虚部能否为负零