私は配列(結果と呼ばれる)を持っています:
@interface FourViewController : UIViewController
{
NSArray *results;
NSMutableData *data;
}
NSURL *url = [NSURL URLWithString:@"http://website/json.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
data = [[NSMutableData alloc] init];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
results = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
}
これをforループで実行すると、配列内のすべてのキーが正しく返され、各JSON文字列は次のようになります。
int i;
for (i = 0; i < [results count]; i++) {
NSLog(@"Result: %i = %@", i, results[i]);
}
ただし、forループ内には次のようなものが必要ですが、それを行うためのドキュメントが見つかりません。
int i;
for (i = 0; i < [results count]; i++) {
location.latitude = results[i][lat];
location.longitude = results[i][long];
myAnn.coordinate = location;
myAnn.title = results[i][title];
myAnn.subtitle = results[i][strap];
[locations addObject:myAnn];
}
lat、long、title、strapはすべてJSONキー/ IDですが、アクセスできません。配列内の各反復内の各キーにアクセスする方法はありますか?