相关疑难解决方法(0)

使用Swift读取JSON文件

我真的很想尝试将一个JSON文件读入Swift,所以我可以玩它.我已经花了2天的时间重新搜索和尝试不同的方法,但没有运气,所以我已经注册StackOverFlow,看看是否有人可以指出我正确的方向.....

我的JSON文件名为test.json,包含以下内容:

{
  "person":[
     {
       "name": "Bob",
       "age": "16",
       "employed": "No"
     },
     {
       "name": "Vinny",
       "age": "56",
       "employed": "Yes"
     }
  ]
}    
Run Code Online (Sandbox Code Playgroud)

该文件直接存储在文档中,我使用以下代码访问它:

let file = "test.json"
let dirs : String[] = NSSearchPathForDirectoriesInDomains(
                                                          NSSearchpathDirectory.DocumentDirectory,
                                                          NSSearchPathDomainMask.AllDomainMask,
                                                          true) as String[]

if (dirs != nil) {
    let directories: String[] = dirs
    let dir = directories[0]
    let path = dir.stringByAppendingPathComponent(file)
}

var jsonData = NSData(contentsOfFile:path, options: nil, error: nil)
println("jsonData \(jsonData)" // This prints what looks to be JSON encoded data.

var jsonDict = …
Run Code Online (Sandbox Code Playgroud)

xcode json nsjsonserialization swift ios8

174
推荐指数
17
解决办法
19万
查看次数

如何知道 WKContentRuleList 阻止了什么

众所周知,我们可以使用 WKContentRuleList 来阻止 url 请求/cookie 或在 WKWebView 中执行其他操作。有什么方法可以根据 WKContentRuleList 知道 WKWebView 阻止了哪些内容吗?

ios wkwebview safari-content-blocker

5
推荐指数
1
解决办法
1310
查看次数