你们能帮我创建使用 ObjectMapper 的以下 JSON 数据的快速对象吗?
[{
"location": "Toronto, Canada",
"three_day_forecast": [
{
"conditions": "Partly cloudy",
"day" : "Monday",
"temperature": 20
},
{
"conditions": "Showers",
"day" : "Tuesday",
"temperature": 22
},
{
"conditions": "Sunny",
"day" : "Wednesday",
"temperature": 28
}
]
}
]
最佳答案
使用 BetterMappable
可以减少大量样板代码这是使用 PropertyWrappers 在 ObjectMapper 上编写的。您需要使用 Swift 5.1 才能使用它。
关于将 JSON 响应数据转换为 swift 对象 [ObjectMapper],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37906690/