【问题标题】:How to use Alamofire with JSONDecoder?如何将 Alamofire 与 JSONDecoder 一起使用?
【发布时间】:2018-05-12 20:05:41
【问题描述】:

我正在尝试如下解析 google Direction API。 https://developers.google.com/maps/documentation/directions/start

但无法从 JSONDecoder 得到任何结果,它总是返回错误块 我正在使用下面的 Alamofire 代码进行解析。

 let decoder = JSONDecoder()
                        do {
                            let userDictionary    =  try   decoder.decode(DirectionParser.self, from: response.data!)
                        print("The Parser \(userDictionary)")

                        } catch {
                            print("Error")
                        }

【问题讨论】:

    标签: alamofire swift4


    【解决方案1】:

    我认为你做得对。只要确保你试图解析你想要的。你可以通过打印出来来做到这一点

    print(response.anythingYouWant)

    你能告诉我们DirectionParser。 确保它像下面的代码

    struct DirectionParse: Decodable {
       //things you want to fetch
    }
    

    P.S 如果我的声望超过 50,我会发表评论。

    【讨论】:

      猜你喜欢
      • 2018-04-24
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多