如何解析内部元素json的内部数组元素

时间:2017-10-25 05:22:22

标签: ios json swift3

this is my JSON response

我想解析这个JSON

Home.swift

  self.resultFromJsonGlobal = (dict?["restaurants"]as?[[String : AnyObject]])!

           // let annotionsArray: NSMutableArray = NSMutableArray()
            for resultFromJson in self.resultFromJsonGlobal

            {
                let socialType = resultFromJson["social_type"]as? String
                let role = resultFromJson["role_code"]as? String
                let Price = resultFromJson["price"]as? Strin
                let rate = resultFromJson["ratings"]as? String
                let ImageUrl = resultFromJson["image"]as? String
                let Discriptions = resultFromJson["descriptions"]as? String
            }

我得到了socialType,role,rate,ImageUrl的价值。但我没有得到价格和描述的价值。

1 个答案:

答案 0 :(得分:0)

试试这段代码。

  self.resultFromJsonGlobal = (dict?["restaurants"]as?[[String : AnyObject]])!

    // let annotionsArray: NSMutableArray = NSMutableArray()
    for resultFromJson in self.resultFromJsonGlobal            
    {
        let socialType = resultFromJson["social_type"] as? String
        let role = resultFromJson["role_code"] as? String
        let rate = resultFromJson["ratings"] as? String
        let ImageUrl = resultFromJson["image"] as? String

        if let items =  resultFromJson["items"] as? [Any]
        {
            for item in items
            {
                let dic = item as! [String:Any]
                let Price = dic["price"] as? String
                let Discriptions = dic["descriptions"] as? String
            }
        }
    }