从Tuple解析JSON数组

时间:2013-08-27 00:19:06

标签: c arrays json tuples pebble-watch

所以我试图在here库旁跟随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 forum问过这个问题。但是没有人回复我的帖子。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

在您的示例中,键“0”与作为嵌套形式的数组相关联。正如httpebble documentation中所解释的那样,字典中没有任何嵌套可以返回到`httpebble。

  

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

您需要重新编写JSON数据以发送与值直接关联的密钥。