首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提取jansson JSON数据

提取jansson JSON数据
EN

Stack Overflow用户
提问于 2016-03-04 22:40:39
回答 1查看 1.6K关注 0票数 1

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

使用https://jansson.readthedocs.org/en/2.7/tutorial.html#the-program相当容易

但是我无法从我的JSON字符串中得到一个简单的int。我可以成功地接收和load一个JSON字符串(就像我没有得到错误,没有什么是null),但是当我使用jansson get函数获得int时,即使使用步骤和断点,jansson函数的int始终是0,而处理an in的jansson函数不返回0。

JSON字符串如下所示:

代码语言:javascript
复制
{"type":3}

以下是代码:

代码语言:javascript
复制
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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-07 21:46:49

我的问题是斯特尔托尔。我不得不重新定义它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35807391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档