在解析中可以解析字典数组吗?

时间:2019-04-25 07:30:07

标签: json swift parse-platform nsmutablearray nsdictionary

我正在使用解析服务器(这是我第一次使用解析)来检索数据并保存。我被困在搜索Web来解析JSON响应的地方,它是一个字典数组。请看下面的JSON

{"delivery_hours":[{"day":"Monday","open":{"hour":"11","minutes":"30","meridian":"am"},"close":{"hour":"9","minutes":"30","meridian":"pm"}},{"day":"Tuesday","open":{"hour":"11","minutes":"30","meridian":"am"},"close":{"hour":"9","minutes":"30","meridian":"pm"}},{"day":"Wednesday","open":{"hour":"11","minutes":"30","meridian":"am"},"close":{"hour":"9","minutes":"30","meridian":"pm"}},{"day":"Thursday","open":{"hour":"11","minutes":"30","meridian":"am"},"close":{"hour":"9","minutes":"30","meridian":"pm"}},{"day":"Friday","open":{"hour":"11","minutes":"30","meridian":"am"},"close":{"hour":"9","minutes":"30","meridian":"pm"}},{"day":"Saturday","open":{"hour":"11","minutes":"30","meridian":"am"},"close":{"hour":"9","minutes":"30","meridian":"pm"}},{"day":"Sunday","open":{"hour":"11","minutes":"30","meridian":"am"},"close":{"hour":"9","minutes":"30","meridian":"pm"}}]}

我正在尝试将日期和OpenTime和CloseTime排列在一起。但是,当我尝试正常方式时,代码崩溃。下面是相同的代码。

let query = PFQuery(className: "ClassName")
    query.order(byAscending: "name")
    query.findObjectsInBackground { (result, error) in
        for object in result! {
          self.restaurantDeliveryTimeArray.add(restaurantDeliveryTime!)
                let restaurantHours = object["delivery_hours"]

                self.restaurnatDeliveryHoursArray.add(restaurantHours!)

                if let dict = self.restaurnatDeliveryHoursArray[0] as? [String:AnyObject] {
                    print(dict)
                }
         }

但这会导致我将数组转换为字典的最后一行崩溃。

请帮助

0 个答案:

没有答案