我正在使用 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/