-1

2 つの質問があります。

1. json から情報をアプリにロードしたいのですが、今は 'NSLog(@"Array: %@", self.news);' です。何も表示されませんが、「(void)connectionDidFinishLoading:(NSURLConnection *)connection」に入れると機能します。理由を教えてください。

//making request query string
NSString *requestUrl = [NSString
                         stringWithFormat:@"%@jsons/json.php?go=product_info&latitude=%g&longitude=%g&identifire=%@&pid=%ld&externalIPAddress=%@&localIPAddress=%@",
                         BASE_URL,
                         coordinate.latitude,
                         coordinate.longitude,
                         uniqueIdentifier,
                         (long)self.productId,
                         [self getIPAddress],
                         [self getLocalIPAddress]
                         ];



NSURL *url=[NSURL URLWithString:requestUrl];
NSURLRequest *request= [NSURLRequest requestWithURL:url];
NSURLConnection *c=[[NSURLConnection alloc] initWithRequest:request delegate:self];

NSLog(@"Array: %@", self.news);



}
//=========================
-(void)connection: (NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{

self.jsonData= [[NSMutableData alloc] init];

}
-(void)connection: (NSURLConnection *)connection didReceiveData:(NSData *)theData{


[self.jsonData appendData:theData];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{


self.news=[NSJSONSerialization JSONObjectWithData:self.jsonData options:nil error:nil];



}

-(void)connection: (NSURLConnection *)connection didFailWithError:(NSError *)error{

UIAlertView *errorView=[[UIAlertView alloc] initWithTitle:@"Error" message:@"download could not be compelete" delegate:nil cancelButtonTitle:@"Dissmiss" otherButtonTitles:nil, nil];
[errorView show];

}

2.このコード行 'self.news=[NSJSONSerialization JSONObjectWithData:self.jsonData options:nil error:なし];'

self.news は辞書に変更した配列ですが、同じ警告メッセージが表示されます。

4

1 に答える 1