问题描述
尝试获取Google Places API调用的结果。这段代码一直工作到几周前。我得到的结果符合Places Struct。
print url行为我提供了一个为我提供json数据的url,但是当我尝试在JSON解码后打印响应时,我得到的是nil。
let session = URLSession(configuration: .default)
func getGooglePlacesData(forKeyword keyword: String,location: CLLocation,withinMeters radius: Int,using completionHandler: @escaping (GooglePlacesResponse) -> ()) {
let url = googlePlacesDataURL(forKey: googlePlacesKey,location: location,keyword: keyword)
let task = session.dataTask(with: url) { (responseData,_,error) in
if let error = error {
print(error.localizedDescription)
return
}
let decoder = JSONDecoder()
print(url)
guard let data = responseData,let response = try? decoder.decode(GooglePlacesResponse.self,from: data) else {
completionHandler(GooglePlacesResponse(results:[]))
return
}
completionHandler(response)
}
task.resume()
}
我们应该如何解码JSON数据?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)