2012-05-18 44 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