2016-11-28 6 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もう1つのjsonをもう一度取得する前に、そこにタスクが必要です。しかし、私はそれが決してコードブロックの中に入ることはできません

答えて

0

私のendPointの空白文字を%20で置換することで問題を解決しました。

関連する問題