2012-05-18 43 views
-2

我已經搜索完整的Google搜索。但沒有找到答案。 我在解析json結果中的對象數組時遇到了問題。 我有這樣的JSON結果:想要使用json for ios5獲取對象數組

[{ 「created_at」: 「星期六4月28日13時36分24秒+0000 2012」, 「文」:「@ LisaPrejean愛你的工作做得很好! 「, 」source「:」web「,」user「:{」id「:478983313,」name「:」3rd Dimension Media「, 」created_at「:」Mon Jan 30 21:51:20 +0000 2012「 「favourites_count」:0}, 「retweet_count」:0}]

&從結果我想etract只有 「created_at」 & 「文本」

  • (無效)connectionDidFinishLoading:(NSURLConnection的*)連接 {
    的NSString * jsonString = [[NSString的頁頭] initWithData:jsonData編碼:NSUTF8StringEncoding]; NSLog(@「%@」,jsonString); self.jsonData = nil;

    NSArray *tweetArray = [jsonString JSONValue]; 
    tweetTextArray = [NSMutableArray array]; 
    for (NSDictionary *tweet in tweetArray) 
    

    { [tweetTextArray ADDOBJECT:[鳴叫objectForKey:@ 「文本」]]; [tweetCreated_atArray addObject:[tweet objectForKey:@「created_at」]]; } }

但得到在線EXC_BAD_ACCESS錯誤: 的NSArray * tweetArray = [jsonString JSONValue];

+0

你看這個[教程](http://www.raywenderlich.com/5492/working-with-json-in-ios-5)? – mprivat

+0

嘗試過但出現錯誤 – amrita

+0

錯誤是什麼? – mprivat

回答

-1

試試這個

NSString *responseString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
SBJSON *parser = [[SBJSON alloc] init]; 
NSDictionary *data = (NSDictionary *) [parser objectWithString:responseString error:nil]; 
NSString *text = (NSString *) [data objectForKey:@"text"]; 
NSLog(@"textvalue= %@",text); 
NSString * created_at = (NSString *) [data objectForKey:@"created_at"]; 
NSLog(@"created_at= %@",created_at); 
+0

出現錯誤 - 「使用未聲明標識符'pareser';你的意思是'暫停'嗎?「 – amrita

+0

你是否下載json庫? – akk

+0

yes從以下鏈接使用:https://github.com/stig/json-framework – amrita