我试图使用swift 4并使用解码来解析一些json。我很困惑的是
打算解码Dictionary
,但找到一个数组。”,underlyingError:nil))
我一般不熟悉使用解码,而一般来说,它都是新的,所以我想知道为什么我会得到这个错误,因为我认为我并不是在以正确的方式定义结构。
这就是我定义结构的方式
1,2,3,...
这就是我使用解码功能的方式
struct QuizDesc: Decodable {
let title: String
let desc: String
let questions: [Questions]
}
struct Questions: Decodable {
let text: String
let answer: Int
let answers: [Answers]
}
struct Answers: Decodable {
let answerOne: String
let answerTwo: String
let answerThree: String
let answerFour: String
}
这是我用来提取json数据的链接 http://tednewardsandbox.site44.com/questions.json
答案 0 :(得分:0)
您的JSON是QuizDesc
的数组。将QuizDesc.self
更改为[QuizDesc].self
。然后将quiz
重命名为quizzes
。