2012-07-17 50 views
1

我想解析這個JSON YouTube recently featured。 這是我得到的視頻標題:解析JSON:括號中的迴應

NSString *response = [request responseString]; 
    responseDict = [response JSONValue]; 

videoTitleArray = [responseDict valueForKeyPath:@"feed.entry.title.$t"]; 

和它的作品就像我想讓它。 但我也想顯示視頻的作者。 但對於這個下面的代碼不能正常工作:

videoAuthorArray = [responseDict valueForKeyPath:@"feed.entry.author.name.$t"]; 
    NSLog(@"%@", videoAuthorArray); 

作者我得到的名單看起來是這樣的:

(
    author 1 
), 
    (
    author 2 
), 
    (
    author 3 
), 
    (
    author 4 
), 

我不能在例如表視圖中顯示的名稱由於括號。 如何顯示作品名稱(如視頻標題)?

回答

3

當看到一個作者你看到這一點:

"author":[{"name":{"$t":"mls"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/mls"},"yt$userId":{"$t":"SZbXT5TLLW_i-5W8FZpFsg"}}] 

這意味着:作者是作者對象的數組

每個作者對象具有:name對象,uri對象和yt$userId對象

上面描述的這些目的中的每一個都是NSDictionary

forma泰德我們:

"author":[ 
    { 
    "name": { 
     "$t":"mls" 
    }, 
    "uri": { 
     "$t":"http://gdata.youtube.com/feeds/api/users/mls" 
    }, 
    "yt$userId":{ 
     "$t":"SZbXT5TLLW_i-5W8FZpFsg" 
    } 
    } 
], 

,所以如果你有你的videoAuthorArray每個元素是一個NSDictionary,有這個按鍵:nameuriyt$userId

每個這種對象有一個關鍵的NSDictionary$t女巫有價值

+0

謝謝!現在我得到了一切工作,現在我想要它。 – derFalke 2012-07-17 18:57:45

+0

你不受歡迎... – 2012-07-17 19:06:09