Как получить элементы из NSArray - PullRequest
2 голосов
/ 07 февраля 2012

У меня есть NSArray, созданный из данных json из Twitter REST API.

NSArray *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];

NSLog (@"Element %@", [dict objectAtIndex: 1]);

Как получить отдельные элементы из массива, один из элементов индекса массива выглядит так:

Element 1 = {
    contributors = "<null>";
    coordinates = "<null>";
    "created_at" = "Tue Feb 07 11:15:08 +0000 2012";
    entities =     {
        hashtags =         (
        );
        urls =         (
        );
        "user_mentions" =         (
        );
    };
    favorited = 0;
    geo = "<null>";
    id = 166842424398848000;
    "id_str" = 166842424398848000;
    "in_reply_to_screen_name" = "<null>";
    "in_reply_to_status_id" = "<null>";
    "in_reply_to_status_id_str" = "<null>";
    "in_reply_to_user_id" = "<null>";
    "in_reply_to_user_id_str" = "<null>";
    place = "<null>";
    "retweet_count" = 0;
    retweeted = 0;
    source = web;
    text = "another day is here so ready to be off from work already...";
    ....

Ответы [ 2 ]

6 голосов
/ 07 февраля 2012

Вы можете попробовать,

NSString *string = [[dict objectAtIndex: 1] objectForKey:@"keyName"];

В ваших данных есть подсловарь, если я правильно выгляжу ("сущности")

NSDictionary *entitiesDict = [[dict objectAtIndex: 1] objectForKey:@"entities"];

Используйте NSDictionary, как упоминалось:)

0 голосов
/ 07 февраля 2012

Используйте NSDictionary вместо NSArray и установите значения для элементов в ключе.проверьте эту ссылку для получения дополнительной идеи.

http://www.touch -code-magazine.com / tutorial-fetch-and-parse-json /

...