c-从Tuple解析JSON数组



因此,我尝试在httpebble库的旁边使用Pebble SDK。

假设DictionaryIterator* received包含以下JSON有效载荷:

{"0":["Oz Lotto","Powerball","TattsLotto","Super 66","Monday & Wednesday Lotto","The Pools"],"1":["17, 26, 38, 7, 36, 45, 9 (44) (41)","15, 37, 32, 6, 24, 10 (11)","37, 12, 15, 16, 42, 45 (6) (9)","1, 8, 5, 8, 8, 5","16, 40, 44, 8, 24, 15 (39) (3)","5, 17, 20, 22, 27, 31 (16)"]}

main.c:

我希望能够提取数据,以便稍后将其存储到我的Pebble应用程序中的列表中。不过,我在理解Tuple是如何工作的方面有点困难。

这就是我目前所掌握的,只是我不确定如何从lotto_nameslotto_numbers中实际提取值。

void http_success(int32_t request_id, int http_status, DictionaryIterator* received, void* context) {
    if (request_id != HTTP_COOKIE) {
        return;
    }
    Tuple *lotto_names = dict_find(received, 0);
    Tuple *lotto_numbers = dict_find(received, 1);
    for (int i = 0; i < 5; i++) {
        const char* lotto_name = lotto_names[i]; // ?
    }
}

我在Pebble SDK论坛上也问过这个问题。然而,没有人回复我的帖子。如有任何帮助,我们将不胜感激。

在您的示例中,键"0"与一个数组相关联,该数组是一种嵌套形式。正如httpebble文档中所解释的,在返回到"httpebble"的字典中不能有任何嵌套。

附加到请求的键/值对作为一个平面JSON字典发送。不能有任何嵌套。

您需要重新处理JSON数据,以发送与值直接关联的键。

最新更新