从本地json获取地址

时间:2018-06-01 07:35:21

标签: ios json

我有这样的代码,json文件格式低于并希望从本地文件中获取

json格式:

{"":[{"name":"","phone":"","address":"","landmark":"","mainarea":""}

代码:

func loadAllContacts(){
        let cityCode = UserDefaults.standard.value(forKey: "selectedLocationCode")
        mainArray = self.loadJSONData(fileCode: cityCode as! String).allValues as! [[String : AnyObject]]
        for i in 0..<mainArray.count{

            if let dict  = mainArray[i] as [String:AnyObject]?{

                for (key,_) in dict{

                    self.allContactsArray[key] = dict[key]

                }
            }
        }
        let contacts = allContactsArray as NSDictionary
        allContactNames = contacts.allKeys as NSArray
        print(allContactNames)
        print(allContactsArray)
    }

1 个答案:

答案 0 :(得分:0)

您的JSON格式无效。也许,这是正确的JSON,你想要的不是吗?

{
    "": [
        {
            "name": "",
            "phone": "",
            "address": "",
            "landmark": "",
            "mainarea": ""
        }
    ]
}