-2

我搜索了完整的谷歌搜索。但没有找到答案。我在从 json 结果解析对象数组时遇到问题。我有这样的json结果:

[{"created_at":"Sat Apr 28 13:36:24 +0000 2012", "text":"@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}]

&从结果中我只想提取“created_at”和“text”

  • (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; NSLog(@"%@", jsonString); self.jsonData = nil;

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

    { [tweetTextArray addObject:[tweet objectForKey:@"text"]]; [tweetCreated_atArray addObject:[tweet objectForKey:@"created_at"]]; } }

但在线出现 EXC_bad_access 错误: NSArray *tweetArray = [jsonString JSONValue];

4

1 回答 1

-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);
于 2012-05-18T12:38:06.840 回答