我正在尝试解析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"];
答案 0 :(得分:2)
可能问题是:
NSDictionary *dit=[[[NSDictionary alloc]init]autorelease];
dit=[str1 JSONValue];
您创建一个空字典,然后从不使用它,而是使用从JSONValue返回的值覆盖该值。此代码应为:
NSDictionary *dit=[str1 JSONValue];