我正在使用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字符串如下所示:
{"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
}发布于 2016-03-07 21:46:49
我的问题是斯特尔托尔。我不得不重新定义它。
https://stackoverflow.com/questions/35807391
复制相似问题