Domanda

So I'm trying to follow the Pebble SDK over here alongside the httpebble library.

Assume DictionaryIterator* received contains the following JSON payload:

{"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:

I want to be able to extract the data to later store them into a list in my Pebble app. I'm having a bit of trouble grasping how a Tuple works though.

This is what I have so far, except I'm afraid I'm not sure how to actually extract values out of lotto_names and 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]; // ?
    }
}

I've also asked the question over at the Pebble SDK forum. However noone has responded to my post. Any help would be appreciated.

È stato utile?

Soluzione

In your example, the key "0" is associated to an array which is a form of nesting. As explained in httpebble documentation, there cannot be any nesting in the dictionary you return to `httpebble.

The key/value pairs attached to the request are sent as a flat JSON dictionary. There cannot be any nesting.

You need to rework your JSON data to send keys associated directly with values.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top