-2

I am using AFNetworking for JSON parsing in my application.here is my response feed

{
    "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"
            }]
        }
    }
}

I want to get count and created field. I have tried but I am getting nil values.

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()
    }
user12346
  • 107
  • 1
  • 3
  • 11
  • Why not use Alamofire 4.0? It's made for swift: https://github.com/Alamofire/Alamofire Made by the same guys that made AFNetworking. – Brandon Oct 24 '17 at 13:28
  • Yes I know but i am unable to set it up since i am facing some proxy issues. – user12346 Oct 24 '17 at 13:44

1 Answers1

0

May be you just forgot import AFNetworking?

FuzzzzyBoy
  • 148
  • 1
  • 13
  • This is my feed URL.Can you please let me know that how can i parse it? https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22AAPL%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback= – user12346 Oct 24 '17 at 13:46
  • { "query": { "count": 1, "created": "2017-10-24T13:05:28Z", "lang": "en-US", "diagnostics": { "redirect": [{ "from": "test" }] } } } – user12346 Oct 24 '17 at 13:52