从 Feed 获取数据
Get data from Feed
我正在使用 AFNetworking 进行 JSON 解析,application.here 是我的响应提要
{
"query": {
"count": 1,
"created": "2017-10-24T13:05:28Z",
"lang": "en-US",
"diagnostics": {
"redirect": [{
"from": "test.com",
"status": "307",
"content": "test.com"
}, {
"from": "test.com",
"status": "307",
"content": "test.com"
}]
}
}
}
我想获取计数和创建字段。
我试过了,但我得到的是零值。
func getJson() {
let configuration = URLSessionConfiguration.default
let manager = AFURLSessionManager(sessionConfiguration: configuration)
let targetURL = URL(string: url)
let request = URLRequest(url: targetURL!)
let dataTask = manager.dataTask(with: request, completionHandler: {(_ response: URLResponse, _ data: Any, _ error: Error?) -> Void in
guard let dict: [String: Any] = data as? [String : Any] else{
return
}
print(dict)
print(dict["count"] as? Int as Any)
guard let dataString = dict["query"] as? [String : Any] else{
return
}
print(dataString)
})
dataTask.resume()
}
你可能只是忘了导入 AFNetworking?
我正在使用 AFNetworking 进行 JSON 解析,application.here 是我的响应提要
{
"query": {
"count": 1,
"created": "2017-10-24T13:05:28Z",
"lang": "en-US",
"diagnostics": {
"redirect": [{
"from": "test.com",
"status": "307",
"content": "test.com"
}, {
"from": "test.com",
"status": "307",
"content": "test.com"
}]
}
}
}
我想获取计数和创建字段。 我试过了,但我得到的是零值。
func getJson() {
let configuration = URLSessionConfiguration.default
let manager = AFURLSessionManager(sessionConfiguration: configuration)
let targetURL = URL(string: url)
let request = URLRequest(url: targetURL!)
let dataTask = manager.dataTask(with: request, completionHandler: {(_ response: URLResponse, _ data: Any, _ error: Error?) -> Void in
guard let dict: [String: Any] = data as? [String : Any] else{
return
}
print(dict)
print(dict["count"] as? Int as Any)
guard let dataString = dict["query"] as? [String : Any] else{
return
}
print(dataString)
})
dataTask.resume()
}
你可能只是忘了导入 AFNetworking?