gpt4 book ai didi

ios - 是否可以使用 ObjectMapper 创建 JSON?

转载 作者:行者123 更新时间:2023-11-30 11:31:01 25 4
gpt4 key购买 nike

我正在开发一个类似于亚马逊的电子商务应用程序,我需要使用字典数组创建 JSON。例如:

    {
"products": [
{
"product_id":1,
"quantity":2
},
{
"product_id":2,
"quantity":2
}
]
}

ObjectMapper框架可以吗?产品是动态生成的,而不是固定数量的产品。每次我们结帐时,产品列表都会根据用户选择而有所不同。

最佳答案

直接回答你的问题..是的。项目上是这样说的homepage :

你可以这样做:

let JSONString = user.toJSONString(prettyPrint: true)

let JSONString = Mapper().toJSONString(user, prettyPrint: true)

对于 Swift 4,请使用 Codable 协议(protocol)和 JSONEncoder()。请参阅Encoding and Decoding Custom Types

关于ios - 是否可以使用 ObjectMapper 创建 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50255191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com