升级Xcode 7后加载错误本地json文件

时间:2015-10-11 09:54:06

标签: ios json xcode

我有位于Xcode内部的json文件。我向UITableView显示信息,直到升级Xcode 7.你能告诉我如何解决这个问题吗?

以下是json文件的示例内容;

json file

[
{
“title”: “School”,
“name”: [“Kyle”, “Joy”, “Melissa”],
},
{
“title”: “Job”,
“name”: [“Michael”, “Eric”, “Nichol”]
}

]

and here is how i could load data before upgrade Xcode;

lazy var stories : [AnyObject] = {
        let path = NSBundle.mainBundle().pathForResource("Stories", ofType: "json")
        let data = NSString(contentsOfFile: path!, encoding: NSUTF8StringEncoding, error: nil)

        let result = data?.dataUsingEncoding(NSUTF8StringEncoding)
        let json : [AnyObject]! = NSJSONSerialization.JSONObjectWithData(result!, options: NSJSONReadingOptions.MutableContainers, error: nil) as! [AnyObject]

        return json
    }()

1 个答案:

答案 0 :(得分:0)

主要原因是由于NSAppTransportsecurity,因此您需要在xcode7中将以下内容添加到项目中。 在Info.plist中添加NSAppTransportSecurity As Dictionary& child as NSAllowsArbitraryLoads As Boolean值为YES