我将如何与没有钥匙的JSON合作:使用urlsession在Swift中的价值对?
我正在尝试在返回的JSON中访问每个标题。这是JSON
[
"Hyouka",
"Youjo Senki",
"Bungou Stray Dogs 2nd Season",
"Fullmetal Alchemist: Brotherhood",
"Tokyo Ghoul √A",
"Mahouka Koukou no Rettousei",
"Boku wa Tomodachi ga Sukunai NEXT",
"Joker Game",
"Avatar: The Last Airbender",
"Charlotte"
]
,这只是一堆值,我没有钥匙来构建我的模型对象。这就是我打算这样做的方式,
struct AllNames {
let name: String
}
但是没有关键名称可以访问。您将如何访问此数据将每个名称打印到Swift中的控制台?
I am trying to access each title in a returned json. This is the JSON
[
"Hyouka",
"Youjo Senki",
"Bungou Stray Dogs 2nd Season",
"Fullmetal Alchemist: Brotherhood",
"Tokyo Ghoul √A",
"Mahouka Koukou no Rettousei",
"Boku wa Tomodachi ga Sukunai NEXT",
"Joker Game",
"Avatar: The Last Airbender",
"Charlotte"
]
It's just a bunch of values and no key for me to construct my model object. This is how I would plan to do it
struct AllNames {
let name: String
}
But there's no key name for me to access. How would you go about accessing this data to print each name to the console in Swift?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的JSON是一系列字符串,因此没有模型,您只需要
Your json is an array of strings , so no model is here and you only need
将JSON字符串转换为数组:
测试案例:
打印日志:
Convert JSON string to array:
Test case:
Print log: