要加载多个 NSURLSession Json

Multiple NSURLSession to load Json

我要加载两个NSURLSession。问题是在第二个 NSURLSession 中我需要一个由第一个 NSURLSession.

给出的密钥

这就是我所做的,但它似乎不起作用!

NSURLSession.sharedSession().dataTaskWithURL(url!) { (data, response, error) in
     do {

let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers)

// fetching items from json ...

for item in items {


 // I extract an ID from each item

 let myID = item["id"] as! String
  /* Here is the problem I want to call another NSURLSession with 
   a url that contains this myID (String) */



 let url2 = NSURL(string:"http://example.com/something?ID=\(myID)")
 NSURLSession.sharedSession().dataTaskWithURL(url2!) { (data2, response2, error2) in
     do {

   //The problem is that this code is not executed in each for loop !

       } catch let jsonError2 {
            print(jsonError2)
        }  

}.resume()





  }

       } catch let jsonError {
            print(jsonError)
        }  

}.resume()

我该怎么办?

对于那些感兴趣的人,解决方案是保留这段代码并添加一个对数组中的数据进行排序的函数。