「IOS入門」NSDataからNSDictionaryへ変換(ネットワーク同期get方法を利用)
コード下記:
– (void)getJsonForData
{
for (NSDictionary *dic in self.dataArray) {
NSString *str = [dic objectForKey:@"url"];
NSURL *url = [NSURL URLWithString:str];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:60.0f];
[request setHTTPMethod:@"GET"];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSLog(@"%@", dic);
[self.jsonArray addObject:dic];
}
[self.tableView reloadData];
}