gpt4 book ai didi

swift - 如何使用来自像 turbo 360 这样的在线服务器的 JSON 文件?

转载 作者:行者123 更新时间:2023-11-28 07:22:20 25 4
gpt4 key购买 nike

I am using a do catch scenario to try a JSONDecoder(), the only >problem is that I keep catching the error, but when I review my code I >can't see the error, maybe I need another set of eyes to help me out >of this one!

我将我的 JSON 文件放在 turbo360 的一个存储文件夹中,我也尝试过 gitHub,但我相信两者都不起作用。

import UIKit

class ViewController: UIViewController {

final let url = URL(string: "https://storage.turbo360.co/portfolio-website-hxoc6m/actors")

override func viewDidLoad() {
super.viewDidLoad()
downloadJson()
}

func downloadJson() {
guard let downloadURL = url else { return }
URLSession.shared.dataTask(with: downloadURL) { data, urlResponse, error in
guard let data = data, error == nil, urlResponse != nil else {
print("something is wrong")
return
}
print("downloaded")
print(downloadURL)
do
{
let decoder = JSONDecoder()
let actors = try decoder.decode(Actors.self, from: data)
print(actors)
} catch {
print("Something wrong after downloaded")
}
}.resume()
}
}

I supposed to get: JSONDonloadingSwift4.Actors as confirmation that my JSON file has been accessed and decoded

最佳答案

您的 JSON 无效。您缺少最后一个图像 URL 上的开头 "。修复该问题,只要您的 Actor 定义匹配,您就应该没问题。jsonlint 对于检查 JSON 非常有用结构。

关于swift - 如何使用来自像 turbo 360 这样的在线服务器的 JSON 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57716936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com