2016-03-01 45 views
-1
Alamofire.request(.GET, gaode, parameters: ["location": location,"key":key]) 
     .responseJSON { response in 
      guard response.response?.statusCode == 200 else{ 
       return 
      } 
      js = JSON(response.result.value!) 
      guard js["infocode"].string! == "10000" else 
      { 
       return 
      } 
      print("JSON: \(js)") 
      guard js["regeocode"]["formatted_address"].string != nil else{ 
       return 
      } 
      print(js["regeocode"]["formatted_address"].string) 
    } 
    return js["regeocode"]["formatted_address"].string! 

代碼在得到響應之前執行return js["regeocode"]["formatted_address"].string!。 爲什麼?我想在返回之前獲取JSON。 如何解決這個問題?爲什麼阿拉莫菲爾早退?

+0

因爲是異步請求。 –

回答

0

返回值位於響應塊之外,因此它將完全獨立於網絡請求返回。

+0

如果我需要回報,如何解決? – zandhappy