2011-10-09 35 views
0

很抱歉的長期問題,但最能概括我想做的事:如何從使用JSONKit創建的NSDictionary正確地填充UITableView NSArray?

我的JSON的樣子:

{ 
    4e8cf1d6c7e24c063e000000 =  { 
     "_id" =   { 
      "$id" = 4e8cf1d6c7e24c063e000000; 
     }; 
     author = faisal; 
     comments =   (
         { 
       author = adias; 
       comment = amazing; 
      }, 
         { 
       author = nike; 
       comment = "I concur"; 
      } 
     ); 
     created =   { 
      sec = 1317772800; 
      usec = 0; 
     }; 
     text = "This is a random post"; 
     title = "post # 1"; 
     type =   (
      punjabi 
     ); 
    }; 
    4e91fd49c7e24cda74000000 =  { 
     "_id" =   { 
      "$id" = 4e91fd49c7e24cda74000000; 
     }; 
     author = draper; 
     comments =   (
         { 
       author = adias; 
       comment = "amazing again"; 
      } 
     ); 
     created =   { 
      sec = 1318118400; 
      usec = 0; 
     }; 
     text = "This is a random post again"; 
     title = "post # 2"; 
     type =   (
      punjabi 
     ); 
    }; 
} 

我想什麼做的是最終具有由具有各行的UTTableview標題(文本從上面JSON):

這是我的代碼至今:

NSString *responseString = [request responseString]; 

    NSDictionary *resultsDictionary = [responseString objectFromJSONString]; 

如何把一切都很g在UITableView的數組中?再次,我只是有點生疏,因爲我可以發誓我以前做過。

回答

1

如果您不需要密鑰,那麼你可以將其轉換爲一個數組使用allValues,如:

NSArray *values = [resultsDictionary allValues]; 
+0

如果你需要鍵值,你也可以使用'[resultsDictionary allKeys]' – simonbs

0

你是否真的JSON解析到一個NSDictionary,或這是一個包含的NSDictionary實例一個NSArray ?如果後者不是這樣的話:

NSString *textForCell = [[resultsArray objectAtIndex:row] valueForKey:@"title"];