1
因此,我試圖通過here旁邊的httpebble庫跟蹤Pebble SDK。從Tuple解析JSON數組
假設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:
我希望能夠提取數據後它們存儲到我的卵石列表應用程序。我在抓住Tuple
的工作原理時遇到了一些麻煩。
這是我到目前爲止,除了恐怕我不知道如何實際提取值從lotto_names
和lotto_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的問題。然而,沒有人回覆我的帖子。任何幫助,將不勝感激。
看看該SDK,它看起來不像一個簡單的JSON工具。它看起來像字典需要數字鍵來表示數據。 「0」和「1」是否轉換爲字典鍵,並將值作爲字符串存儲在字典中?也許一個JSON庫會很好用。 – ash
@ash:好的問題,我正在使用名爲[httpebble](https://github.com/Katharine/httpebble-watch)的庫,我相信這樣做。 – fuzz
我在字典的API中沒有看到它,但我可能會錯過它。這裏有一個很棒的JSON引用網站:http://json.org/。下面是我相信我從那裏使用的一個:https://github.com/json-c/json-c/wiki。請注意,我以前嘗試使用的一些庫並未正確處理引號。希望這可以幫助。 – ash