【发布时间】:2025-11-29 03:50:01
【问题描述】:
所以我试图通过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_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:很好的问题,我正在使用一个名为 httpebble 的库,我相信它可以做到这一点。
-
我没有在字典的 API 中看到它,但我可能会错过它。这是一个很棒的 JSON 参考网站:json.org。这是我相信我从那里使用过的一个:github.com/json-c/json-c/wiki。请注意,我过去尝试使用的一些库没有正确处理引用。希望这会有所帮助。
标签: c arrays json tuples pebble-watch