2011-11-19 81 views
0

我想在我的UITableView中顯示來自disqus.com的評論。NSDictionary到NSArray並返回到NSDictionary

現在我有:1。

//Creating NSArray with comments only from NSDictionary Dict 
    comments = [dict objectForKey:@"response"]; 
      NSLog(@"MessageArray:%@ count:%i", comments, [comments count]); 
      [tableViewNew reloadData]; 

2.

//I'm trying to get NSDictionary from NSArray, but it isn't work 
NSDictionary *currentComment = [comments objectAtIndex:indexPath.row]; 
//currentComment = nil 

在我的* .h文件,我有這樣的:

NSArray* comments; 
@property (retain, nonatomic) NSArray* comments; 

而且我的意見陣列的文字:

(
     { 
     author =   { 
      about = ""; 
      avatar =    { 
       cache = "http://mediacdn.disqus.com/1321567697/images/noavatar92.png"; 
       permalink = "http://disqus.com/api/users/avatars/itruf.jpg"; 
      }; 
      emailHash = 7741f7b9bbf2a05ff782550412b9a513; 
      id = 16898031; 
      isAnonymous = 0; 
      joinedAt = "2011-09-17T17:17:16"; 
      name = itruf; 
      profileUrl = "http://disqus.com/itruf/"; 
      url = ""; 
      username = itruf; 
     }; 
     createdAt = "2011-11-19T06:28:28"; 
     dislikes = 0; 
     forum = smartfiction; 
     id = 368112946; 
     isApproved = 1; 
     isDeleted = 0; 
     isEdited = 0; 
     isFlagged = 0; 
     isHighlighted = 0; 
     isJuliaFlagged = 1; 
     isSpam = 0; 
     likes = 0; 
     media =   (
     ); 
     message = "\U0422\U0435\U0441\U0442. \U041f\U0440\U043e\U0448\U0443 \U043d\U0435 \U0433\U043d\U0435\U0432\U0430\U0442\U044c\U0441\U044f.<br><br><br><br>!!!!!!<br><br>\U0410\U0430 \U0411\U0431 \U0412\U0432 \U0413\U0433 \U0414\U0434 \U0415\U0435 \U0401\U0451 \U0416\U0436 \U0417\U0437 \U0418\U0438 \U0419\U0439 \U041a\U043a \U041b\U043b \U041c\U043c \U041d\U043d \U041e\U043e \U041f\U043f \U0420\U0440 \U0421\U0441 \U0422\U0442 \U0423\U0443 \U0424\U0444 \U0425\U0445 \U0426\U0446 \U0427\U0447 \U0428\U0448 \U0429\U0449 \U042a\U044a \U042b\U044b \U042c\U044c \U042d\U044d \U042e\U044e \U042f\U044f"; 
     parent = "<null>"; 
     points = 0; 
     "raw_message" = "\U0422\U0435\U0441\U0442. \U041f\U0440\U043e\U0448\U0443 \U043d\U0435 \U0433\U043d\U0435\U0432\U0430\U0442\U044c\U0441\U044f.\n\n\n\n!!!!!!\n\n\U0410\U0430 \U0411\U0431 \U0412\U0432 \U0413\U0433 \U0414\U0434 \U0415\U0435 \U0401\U0451 \U0416\U0436 \U0417\U0437 \U0418\U0438 \U0419\U0439 \U041a\U043a \U041b\U043b \U041c\U043c \U041d\U043d \U041e\U043e \U041f\U043f \U0420\U0440 \U0421\U0441 \U0422\U0442 \U0423\U0443 \U0424\U0444 \U0425\U0445 \U0426\U0446 \U0427\U0447 \U0428\U0448 \U0429\U0449 \U042a\U044a \U042b\U044b \U042c\U044c \U042d\U044d \U042e\U044e \U042f\U044f"; 
     thread = 475714714; 
    }, 
     { 
     author =   { 
      avatar =    { 
       cache = "http://www.gravatar.com/avatar.php?gravatar_id=2c5d4ef0caae2eb294f9f85cff0fa88b&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png"; 
       permalink = "http://www.gravatar.com/avatar.php?gravatar_id=2c5d4ef0caae2eb294f9f85cff0fa88b&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png"; 
      }; 
      emailHash = 2c5d4ef0caae2eb294f9f85cff0fa88b; 
      isAnonymous = 1; 
      name = "\U0421\U0435\U0440\U0433\U0435\U0439"; 
      profileUrl = "http://disqus.com/guest/2c5d4ef0caae2eb294f9f85cff0fa88b/"; 
      url = ""; 
     }; 
     createdAt = "2011-11-18T07:36:47"; 
     dislikes = 0; 
     forum = smartfiction; 
     id = 367328215; 
     isApproved = 1; 
     isDeleted = 0; 
     isEdited = 0; 
     isFlagged = 0; 
     isHighlighted = 0; 
     isJuliaFlagged = 1; 
     isSpam = 0; 
     likes = 1; 
     media =   (
     ); 
     message = "\U041a\U043b\U0430\U0441\U0441!!! \U0420\U0430\U0431\U043e\U0447\U0438\U0439 \U043a\U043e\U043c\U0430\U043d\U0434\U0443\U0435\U0442 \U043c\U0435\U043d\U0435\U0434\U0436\U0435\U0440\U043e\U043c! \U0414\U0430 \U043a\U0430\U043a \U0433\U0440\U0430\U043c\U043e\U0442\U043d\U043e \U043e\U043d \U044d\U0442\U043e \U0434\U0435\U043b\U0430\U0435\U0442! \U0410 \U043c\U0438\U0441\U0442\U0435\U0440 \U0413\U0440\U0438\U043c\U043c\U0435\U0442, \U043f\U043e\U0445\U043e\U0436\U0435, \U0438 \U0432\U043f\U0440\U0430\U0432\U0434\U0443 \U0431\U043e\U043b\U0432\U0430\U043d."; 
     parent = "<null>"; 
     points = 1; 
     "raw_message" = "\U041a\U043b\U0430\U0441\U0441!!! \U0420\U0430\U0431\U043e\U0447\U0438\U0439 \U043a\U043e\U043c\U0430\U043d\U0434\U0443\U0435\U0442 \U043c\U0435\U043d\U0435\U0434\U0436\U0435\U0440\U043e\U043c! \U0414\U0430 \U043a\U0430\U043a \U0433\U0440\U0430\U043c\U043e\U0442\U043d\U043e \U043e\U043d \U044d\U0442\U043e \U0434\U0435\U043b\U0430\U0435\U0442! \U0410 \U043c\U0438\U0441\U0442\U0435\U0440 \U0413\U0440\U0438\U043c\U043c\U0435\U0442, \U043f\U043e\U0445\U043e\U0436\U0435, \U0438 \U0432\U043f\U0440\U0430\U0432\U0434\U0443 \U0431\U043e\U043b\U0432\U0430\U043d."; 
     thread = 475714714; 
    } 
) 

我想從我的數組中使用所有鍵的NSDictionary。 非常感謝。

+0

你可以發佈json的結構嗎?沒有它基本上是一個盲人領導另一個... –

+0

我使用這個API方法:http://disqus.com/api/docs/forums/listPosts/ – werbary

回答

0

你可以試試這個:

NSDictionary *currentComment = [[NSDictionary alloc] initWithDictionary: [comments objectAtIndex:indexPath.row]]; 

我認爲你是在你的「cellForRowAtIndex」的方法使用該...所以,如果在最後的這個方法釋放返回YES到小區前yes..then詞典。否則sometine它可能會給你錯誤或錯誤的數據..快樂編碼:)