【发布时间】:2018-05-09 13:54:50
【问题描述】:
我正在开发一个类似于亚马逊的电子商务应用程序,我需要创建一个带有字典数组的 JSON。 例如:
{
"products": [
{
"product_id":1,
"quantity":2
},
{
"product_id":2,
"quantity":2
}
]
}
ObjectMapper 框架可以吗?产品是动态生成的,而不是固定数量的产品。每次我们结帐时,产品列表都会根据用户的选择而有所不同。
【问题讨论】:
-
对于 Swift 4,使用
Codable协议和JSONEncoder()。见Encoding and Decoding Custom Types
标签: ios json swift objectmapper