JSON解析错误仅与谷歌API其他URL正常工作

时间:2019-02-23 07:29:32

标签: json parsing

这是我实现的代码

导入UIKit 导入SwiftyJSON 导入Alamofire

ViewController类:UIViewController {

let url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Boston,MA|Charlestown,MA&destinations=Lexington,MA|Concord,MA&departure_time=now&key=AIzaSyAbRF7pJJbBkN8nwm9aKTJ4vV7ZD0ZcxAE"

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    //MARK: - Networking
    /***************************************************************/

    //Write the getWeatherData method here:


    func getWeatherData(url: String) {

        Alamofire.request(url, method: .get).responseJSON {
            response in
            if response.result.isSuccess {

                print("Success! Got the weather data")
                let weatherJSON : JSON = JSON(response.result.value!)


                print(weatherJSON)

                //self.updateWeatherData(json: weatherJSON)

            }
            else {
                print("Error \(String(describing: response.result.error))")
                //self.cityLabel.text = "Connection Issues"
            }
        }

    }
     getWeatherData(url: url)

********************************错误********

我仅在使用google api错误时收到此错误,我创建了自己的api并在浏览器中检查了它的运行状况,但在Xcode中我得到了一条错误声明:Error Optional(Alamofire.AFError.invalidURL(url:“ https://maps.googleapis.com/maps/api/distancematrix/json?origins=Boston,MA|Charlestown,MA&destinations=Lexington,MA|Concord,MA&departure_time=now&key=AIzaSyAbRF7pJJbBkN8nwm9aKTJ4vV7ZD0ZcxAE“)) ç

0 个答案:

没有答案