无法使用 json-glib 获取 JsonArray* 中包含的数字

Cannot get numbers contained in a JsonArray* using json-glib

我无法使用 curl 检索从服务器收到的数组响应中包含的值:

struct string data;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data); //response from the server is written to data
curl_easy_perform(curl);
dlog_print(DLOG_DEBUG, LOG_TAG, "%s", data.len, data.ptr);

我成功收到响应,上面的 dlog 打印了以下内容:

{"timestamps":[1486371362000,1486371422000,1486371482000]}

我正在尝试通过执行以下操作打印出 json 数组 "timestamps" 中的值:

JsonParser *parser = json_parser_new();
g_type_init();
json_parser_load_from_data(parser, data.ptr, data.len, &error);
JsonNode *root = json_parser_get_root(parser);
JsonObject *obj = json_node_get_object(root);
JsonArray *array = (JsonArray*)json_object_get_array_member(obj,"timestamps");
json_array_foreach_element(timestamps, forEachJsonElement, NULL);

我的 forEachJsonElement 函数定义如下:

void forEachJsonElement(JsonArray *array, guint index, JsonNode *element_node, gpointer user_data){
    dlog_print(DLOG_DEBUG, LOG_TAG, "forEachJsonElement index: %d", index);
    dlog_print(DLOG_DEBUG, LOG_TAG, "forEachJsonElement value: %f", json_node_get_double(element_node));
}

日志打印:

forEachJsonElement index: 0 
forEachJsonElement value: 0.000000 
forEachJsonElement index: 1 
forEachJsonElement value: 0.000000 
forEachJsonElement index: 2 
forEachJsonElement value: 0.000000

我的问题是,为什么使用 json_node_get_double 这些值总是打印出 0?如何正确检索我在第一个日志中看到的值 1486371362000、1486371422000 和 1486371482000。我已经尝试了 json_node_get_int 以及我能想到的在 json-glib 库中可用的所有其他内容,但似乎 json_node_get_double 总是 returns 0.00000。我需要这个,以便我可以从服务器处理的原始数组中正确删除与这些值匹配的元素。

谢谢!

我会尝试 json_node_get_int 其中 returns 64 位整数。这些对我来说不像双打。

要使整数键正确打印,需要使用格式字符串 "%" G_GINT64_FORMAT 而不是 "%d" 作为从 json_node_get_int() 返回的值,因为它 returns 一个 gint64,而不是一个 gint