-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。 如何解决这个问题?为什么阿拉莫菲尔早退?
因为是异步请求。 –