Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
let path = Bundle.main.path(forResource: "countryData", ofType: "json")
let url = URL(fileURLWithPath: path!)
// 带throws的方法需要抛异常
do {
/*
* try 和 try! 的区别
* try 发生异常会跳到catch代码中
* try! 发生异常程序会直接crash
*/
let data = try Data(contentsOf: url)
let jsonData:Any = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers)
let jsonArr = jsonData as! NSArray
for dict in jsonArr {
print(dict)
}
} catch let error as Error! {
print("读取本地数据出现错误!",error)
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有