1

我正在尝试解析 google api,以便我可以检索地址及其数据。我在注释行中收到两个错误。为什么我会收到这些错误。我分配了dit,所以我必须正确释放它。这是我检索数据的代码

  NSURL *url=[NSURL URLWithString:str];
    NSData *data=[[NSData alloc]initWithContentsOfURL:url];
    NSString *str1=[[[NSString alloc]initWithData:data  encoding:NSUTF8StringEncoding]autorelease];
    NSDictionary *dit=[[[NSDictionary alloc]init]autorelease];//value stored to dit during initialization is never read
    dit=[str1 JSONValue];
    NSArray *dit1=(NSArray *) [dit objectForKey:@"results"];
    NSDictionary *dit3=[[dit1 objectAtIndex:0]objectForKey:@"geometry"];
    NSDictionary *dit4=[dit3 objectForKey:@"bounds"];
    NSDictionary *northeast=[dit4 objectForKey:@"northeast"];
    NSDictionary *lt=[northeast objectForKey:@"lat"];
    NSDictionary *southwest=[dit4 objectForKey:@"southwest"];
    NSDictionary *lng=[southwest objectForKey:@"lng"];
4

1 回答 1

2

问题大概是这样的:

NSDictionary *dit=[[[NSDictionary alloc]init]autorelease];
dit=[str1 JSONValue];

您创建一个空字典,然后从不使用它,而是用从 JSONValue 返回的值覆盖该值。这段代码应该是:

NSDictionary *dit=[str1 JSONValue];
于 2012-07-16T12:10:53.813 回答