2016-11-28 1 views
0

Json에서 GET 메서드를 사용하고 있습니다. GET 메서드는 for 루프 안에 있고 문제는 작업을 완료하지 못하거나 결과를 얻지 못하고 있다는 것입니다. 대신 루프가 증가합니다. 결과 데이터를 NSDictionary로 설정하는 블록 안에 중단 점을 배치했으나 결코 중단되지 않습니다.json을 얻는 중 코드 블록을 기다리는 중 또는 종료하지 않습니다.

GET 메서드를 직접 호출 할 수 있습니까? 코드가 한 줄씩 읽혀질 것입니다. 그리고 json이 처리를 마칠 때까지 건너 뛰거나 대기하지 않습니다. 나는이 라인 NSArray *episodeArray =result;에 브레이크 포인트를 배치 한

- (void)downloadJsonFeed 
{ 
for(int i = 1;i < self.numberOfEpisodes;i++) 
{ 
    NSString *endPoint = [[[[baseJsonUrl stringByAppendingString:getEpisodes]stringByAppendingString:self.title]stringByAppendingString:@"&episodeNumber="]stringByAppendingString:[NSString stringWithFormat:@"%i",i]]; 
    NSLog(@"End point %@",endPoint); 
    [JsonDownload getJson:token andEndpointString:endPoint WithHandler:^(__weak id result) 
    { 
     NSArray *episodeArray =result; 
     //will do some task here 
    }]; 

} 

} 


- (void)getJson:(NSString *)authData andEndpointString:(NSString *)urlString WithHandler:(void(^)(__weak id result))handler 
{ 
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; 
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]]; 
NSURL * url = [NSURL URLWithString:urlString]; 
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url]; 

//NSString *auth = [NSString stringWithFormat:@"Bearer {%@}", authData]; 

[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-type"]; 
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"]; 
[urlRequest setValue:authData forHTTPHeaderField:@"Cookie"]; 
[urlRequest setHTTPMethod:@"GET"]; 

NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest 
                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 
                 if(error == nil) 
                 { 
                  id returnedObject = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableLeaves error:nil]; 
                  handler(returnedObject); 
                 } 
                 else{ 
                  NSLog(@"error %@",error); 
                 } 
                }]; 
[dataTask resume]; 
} 

그리고 간다 결코 :

는 여기에 내가 한 일입니다. 그러나 내가 중단 점을 넣을 때 [JsonDownload getJson:token andEndpointString:endPoint WithHandler:^(__weak id result) 라인에 응답하고있다.

그리고 논평 한 라인에 //will do some task here 또 다른 json을 다시 얻기 전에 작업이 필요하다. 하지만 코드 블록 안에 들어갈 수는 없습니다.

답변

0

endPoint의 공백 문자를 % 20으로 대체하여 문제를 해결했습니다.

관련 문제