2012-02-07 85 views
2

我有一個從twitter REST API的json數據構建的NSArray。如何從NSArray獲取元素

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..."; 
    .... 

回答

6

你可以試試,

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

有一個在你的數據的子字典,如果我看起來正確( 「實體」)

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

使用的NSDictionary作爲提到:)