0
我需要從四個URL中分別獲取單個JSON數據值。我已經寫擺脫單一的URL JSON數據的代碼運行多個網址以獲取多個JSON值
NSString *url=[NSString stringWithFormat:@"http://jsondata.in/UserImage.svc/GetUnAnsweredImagesLogCount?UserId=%@",requestString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"GET"];
NSURLConnection * connReq = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if (connReq) {
NSLog(@"Connection Sucessful");
receivedData = [[NSMutableData alloc]init];
[self facialimagelogcounturl];
}
else
{
NSLog(@"failed");
}
[connReq start];
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"Status code: %ld", (long)[response statusCode]);
NSLog(@"respdata%@",respData);
-(void)connection:(NSURLConnection *)connection didReceiveResponse:
(NSURLResponse *)response
{
[receivedData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:
(NSData *)data
{
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"ERROR");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *e;
NSString *JSON = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];
_userlogcountlabel.text=JSON;
int json=[JSON intValue];
}
我需要顯示在不同的標籤中的數據的每個從單個URL其工作罰款url.For單個取出單個值。我需要爲多個網址製作。
環路爲你有網址的數量。爲每個URL在循環中獲取JSON響應。 –
這裏你只顯示一個網址,你的四個網址在哪裏 –
它在karthik上我有異步請求的答案。我會在幾分鐘後發佈 –