Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用SWIFT解析json内部的多维数组_Ios_Json_Swift_Multidimensional Array - Fatal编程技术网

Ios 如何使用SWIFT解析json内部的多维数组

Ios 如何使用SWIFT解析json内部的多维数组,ios,json,swift,multidimensional-array,Ios,Json,Swift,Multidimensional Array,这是我的示例JSON数据 { "COD": [ { "Merchant": { "MerchantID": "4701", "MerchantCompany": "PAMB", "MerchantName": "Phira", "MerchantSurname": "Mueadnok", "MerchantAddress": "54

这是我的示例JSON数据

{
    "COD": [ {    
        "Merchant": {       
            "MerchantID": "4701",
            "MerchantCompany": "PAMB",
            "MerchantName": "Phira",
            "MerchantSurname": "Mueadnok",
            "MerchantAddress": "54 MT Mansion",
            "MerchantCity": "Huaykwang",
            "MerchantProvince": "Bangkok",
            "MerchantTel": "0816547412"
        },
        "Order": 
        {    
            "OrderID": "875321",
            "ProductName": "SKII miracle water",
            "ProductPrice": "1020",
            "ProductDimention": "10X10X20 [W*H*D]",
            "ProductWeight": "200G",
            "CollectITEM": "0",
            "Deliver": "0"
        },
        "Customer": 
        {
            "CustomerName": "Malee",
            "CustomerSurname": "",
            "CustomerAddress": "54 MT Mansion",
            "CustomerCity": "Huaykwang",
            "CustomerProvince": "Bangkok",
            "CustomerTel": "0816547412"
        }    
    }]
}     
在XCode6.3中

    var endpoint = NSURL(string: /* Link From site */)
    var data = NSData(contentsOfURL: endpoint!)        

    if let json: NSDictionary = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers, error: nil) as? NSDictionary {
        if let items = json["COD"] as? NSArray {
            for item in items{
               println(item["Order"])
                println("_______________________________________")
                if let order = item["Order"] as? NSDictionary {
                    for orderDetail in order {

                        println(orderDetail["OrderID"])
                        // i need to present only OrderID
                    }
                }
            }
        }
    }

我使用的代码是parse JSON数组,但是输出只是“Order”中的列表,我只需要使用“
OrderID
”。有人能帮我解决这个问题吗

试试快速JSON库


它简化了一切

在本例中,“order”是字典而不是数组。因此,您需要将其键入字典而不是数组。嘿。thx nshebbar,但仍然无法取出OrderId您的JSON无效。你在某个地方错过了一个结尾,即使这样?