小编Gui*_*reu的帖子

在swift中创建JSON数组和JSON对象

我想在Swift中做这个JSON.但我不能这样做....

{
    "room": "Platinum",
    "products": [{
        "name": "Agua",
         "quantity": 2
},
{   
    "name":"Cafe",
    "quantity": 4
}],
    "observation": "",
    "date": "2016-08-15 12:00:00"
}
Run Code Online (Sandbox Code Playgroud)

我的快速代码返回:

{
    date = "2016-08-25 18:16:28 +0000";
    observation = "";
    products =     (
            {
                name = cafe;
                quantity = 1;
            }
    );
    room = Platinium;
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

let para:NSMutableDictionary = NSMutableDictionary()
let prod: NSMutableDictionary = NSMutableDictionary()

para.setValue(String(receivedString), forKey: "room")
para.setValue(observationString, forKey: "observation")
para.setValue(stringDate, forKey: "date")

for product in products{
    prod.setValue(product.name, forKey: "name")
    prod.setValue(product.quantity, forKey: "quantity")
    para.setObject([prod], forKey: "products")
} …
Run Code Online (Sandbox Code Playgroud)

json ios swift

3
推荐指数
1
解决办法
8545
查看次数

标签 统计

ios ×1

json ×1

swift ×1