将 JSON 响应数据转换为 swift 对象 [ObjectMapper]

标签 json swift objectmapper

你们能帮我创建使用 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/

相关文章:

json - 字母数字 ID 未映射但给出 Nil 输出

java - 如何在 Angular 5 应用程序中使用 jaxrs (resteasy) 将 Set 或 List 映射到数组?

ios - 如何确保启动屏幕正在显示

ios - 如何快速分离变量并将键设置为 true ?

swift - AR 对象在 RealityKit 中无法正确锚定或调整大小

java - 将 JSON 键值映射到 Java 中的类

java - 使用 ObjectMapper 反序列化具有相同属性但不同类名的多个对象

php - PHP 中的 MySQL 到 JSON

javascript - 迭代 javascript 对象

perl - 用 Perl 解析 JSON 的问题