天気予報アプリケーションの応答を取得するコーディングを行いました。正確な緯度、経度、母集団の値を取得できませんでした。正確な値ではなく、nullとして応答を取得しています。その後、他の応答を取得できません。また、応答は-> "キャッチされなかった例外 'NSRangeException'が原因でアプリを終了しています、理由: ' * -[__ NSArrayM objectAtIndex:]:インデックス1が境界を超えています[0 .. 0]'"配列インデックス形式で何か間違ったことをしました。すべての値?
これは私のコーディングです
.Mパート
-(void)viewDidLoad
{
[super viewDidLoad];
NSMutableURLRequest *request =[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://api.worldweatheronline.com/free/v1/search.ashx?query=London&num_of_results=3&format=json&key=xkq544hkar4m69qujdgujn7w"]];
[request setHTTPMethod:@"POST"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSDictionary *dict1 =[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&err];
//NSDictionary *dict1a =[dict1 objectForKey:@"JSON"];
NSDictionary *dict2 = [dict1 objectForKey:@"search_api"];
NSArray *array1 =[dict2 objectForKey:@"result"];
for(int i=0;i<[array1 count]; i++)
{
NSDictionary *dict3 =[array1 objectAtIndex:i];
NSArray *array2 =[dict3 objectForKey:@"areaName"];
NSDictionary *dict4 =[array2 objectAtIndex:i];
// NSArray *arr3 =[dict4 objectForKey:@"London"];
//manage.transformName= [NSString stringWithFormat:@"%@",[venueNem objectForKey:@"username"]];
NSString *str1= [NSString stringWithFormat:@"%@",[dict4 objectForKey:@"value"]];
NSLog(@"the response ==%@",str1);
NSArray *array3 =[dict3 objectForKey:@"country"];
NSDictionary *dict5 =[array3 objectAtIndex:i];
NSString *str2 =[NSString stringWithFormat:@"%@",[dict5 objectForKey:@"value"]];
NSLog(@"the response ==%@",str2);
NSString *str3 =[NSString stringWithFormat:@"%@",[dict5 objectForKey:@"latitude"]];
NSLog(@"the response ==%@",str3);
NSString *str4 =[NSString stringWithFormat:@"%@",[dict5 objectForKey:@"longitude"]];
NSLog(@"the response ==%@",str4);
NSString *str5 = [NSString stringWithFormat:@"%@",[dict5 objectForKey:@"population"]];
NSLog(@"the response ==%@",str5);
NSArray *arr4 =[dict3 objectForKey:@"region"];
NSDictionary *dict6 =[arr4 objectAtIndex:i];
NSString *str6 = [NSString stringWithFormat:@"%@",[dict6 objectForKey:@"value"]];
NSLog(@"the response ==%@",str6);
NSArray *arr5 =[dict3 objectForKey:@"weatherUrl"];
NSDictionary *dict7 =[arr5 objectAtIndex:i];
NSString *str7 =[NSString stringWithFormat:@"%@",[dict7 objectForKey:@"value"]];
NSLog(@"the response ==%@",str7);
}
for(int j=0;j<[array1 count];j++)
{
NSDictionary *dict8 =[array1 objectAtIndex:j];
NSArray *arr6 =[dict8 objectForKey:@"areaname"];
NSDictionary *dict9 =[arr6 objectAtIndex:j];
NSString *str8 =[NSString stringWithFormat:@"%@",[dict9 objectForKey:@"value"]];
NSLog(@"the response ==%@",str8);
NSArray *arr7 =[dict8 objectForKey:@"country"];
NSDictionary *dict10 =[arr7 objectAtIndex:j];
NSString *str9 =[NSString stringWithFormat:@"%@",[dict10 objectForKey:@"value"]];
NSLog(@"the response ==%@",str9);
NSString *str10 =[NSString stringWithFormat:@"%f",[dict10 objectForKey:@"latitude"]];
NSLog(@"the response ==%@",str10);
NSString *str11 =[NSString stringWithFormat:@"%f",[dict10 objectForKey:@"longitude"]];
NSLog(@"the response ==%@",str11);
NSString *str12 =[NSString stringWithFormat:@"%d",[dict10 objectForKey:@"population"]];
NSLog(@"the response ==%@",str12);
NSArray *arr8 =[dict8 objectForKey:@"region"];
NSDictionary *dict11 =[arr8 objectAtIndex:j];
NSString *str13 =[NSString stringWithFormat:@"%@",[dict11 objectForKey:@"value"]];
NSLog(@"the response ==%@",str13);
NSArray *arr9 =[dict8 objectForKey:@"weatherurl"];
NSDictionary *dict12 =[arr9 objectAtIndex:j];
NSString *str14 =[NSString stringWithFormat:@"%@",[dict12 objectForKey:@"value"]];
NSLog(@"the response ==%@",str14);
}
NSDictionary *dict13 =[array1 objectAtIndex:2];
NSArray *arr10 =[dict13 objectForKey:@"areaname"];
NSDictionary *dict14 =[arr10 objectAtIndex:2];
NSString *str15 =[NSString stringWithFormat:@"%@",[dict14 objectForKey:@"value"]];
NSLog(@"the response ==%@",str15);
NSArray *arr11 =[dict13 objectForKey:@"country"];
NSDictionary *dict15 =[arr11 objectAtIndex:2];
NSString *str16 =[NSString stringWithFormat:@"%@",[dict15 objectForKey:@"value"]];
NSLog(@"the response ==%@",str16);
NSString *str17 =[NSString stringWithFormat:@"%f",[dict15 objectForKey:@"latitude"]];
NSLog(@"the response ==%@",str17);
NSString *str18 =[NSString stringWithFormat:@"%f",[dict15 objectForKey:@"longitude"]];
NSLog(@"the response ==%@",str18);
NSString *str19 =[NSString stringWithFormat:@"%d",[dict15 objectForKey:@"population"]];
NSLog(@"the response ==%@",str19);
NSArray *arr12 =[dict13 objectForKey:@"region"];
NSDictionary *dict16 =[arr12 objectAtIndex:2];
NSString *str20 =[NSString stringWithFormat:@"%@",[dict16 objectForKey:@"value"]];
NSLog(@"the response ==%@",str20);
NSArray *arr13 =[dict13 objectForKey:@"weatherurl"];
NSDictionary *dict17 =[arr13 objectAtIndex:2];
NSString *str21 =[NSString stringWithFormat:@"%@",[dict17 objectForKey:@"value"]];
NSLog(@"the response ==%@",str21); }
arra=[[NSMutableArray alloc]init];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://api.worldweatheronline.com/free/v1/search.ashx?query=London&num_of_results=3&format=json&key=xkq544hkar4m69qujdgujn7w"]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err];
NSArray *array=[[jsonArray objectForKey:@"search_api"]objectForKey:@"result"];
for (int i=0; i<[array count]; i++) {
NSLog(@"the areaName==%@",[[[[array objectAtIndex:i]objectForKey:@"areaName"]objectAtIndex:0]objectForKey:@"value"]);
NSLog(@"the country==%@",[[[[array objectAtIndex:i]objectForKey:@"country"]objectAtIndex:0]objectForKey:@"value"]);
NSLog(@"the latitude==%@",[[array objectAtIndex:i]objectForKey:@"latitude"]);
NSLog(@"the long==%@",[[array objectAtIndex:i]objectForKey:@"longitude"]);
NSLog(@"the pop==%@",[[array objectAtIndex:i]objectForKey:@"population"]);
NSLog(@"the region==%@",[[[[array objectAtIndex:i]objectForKey:@"region"]objectAtIndex:0]objectForKey:@"value"]);
NSLog(@"the url==%@",[[[[array objectAtIndex:i]objectForKey:@"weatherUrl"]objectAtIndex:0]objectForKey:@"value"]);
NSString *areaName=[[[[array objectAtIndex:i]objectForKey:@"areaName"]objectAtIndex:0]objectForKey:@"value"];
[arra addObject:areaName];
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加