我在使用Swift在JSON中创建特定结构时遇到问题。我使用Swifty JSON进行解析,但我无法弄清楚如何创建一个。在Swift中创建特定的JSON结构
我有这个数组,它由产品的Id和数量Ints填充到购物篮中。我需要将数组放入我的JSON中,但我不知道如何。
如果你能帮助我,我会很高兴:)
var productArray = Array<(id: Int,quantity: Int)>()
let jsonObject: [String: AnyObject] = [
"order": 1,
"client" : 1,
"plats": [
for product in productArray
{
"id": product.id
"quantity": product.quantity
}
]
]
此代码是否正在编译? – Blackus
不行,只是“在容器文字预期的表达式”在行,我不知道如何做到这一点 – Dinosan0908
你有'for'循环'''''''',这是绝对不允许的。你想要他们'平台'钥匙的价值是什么? – ABakerSmith