我遇到了NSDictionary for循环的问题。这本词典被称为“海滩”,但在循环海滩内是未申报的。这是代码
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSArray *results = [jsonString JSONValue];
for (NSDictionary *beach in results); //beach is flagged as unused
{
NSString *Name = [beach objectForKey:@"Name"]; //beach is flagged as undeclared
NSLog(Name);
}
}
任何建议都会很棒。
答案 0 :(得分:2)
您的for
声明中有一个虚假的分号:
for (NSDictionary *beach in results);
// ^
这使您的代码等同于:
for (NSDictionary *beach in results)
;
{
NSString *Name = [beach objectForKey:@"Name"];
NSLog(Name);
}