jeudi 30 juin 2016

Json web-service Swift [on hold]


I'm starting developing an app on iOS, and one of the points is to try to get information from one web-service, the function i'm running returns the error below:

ErrorCould not parse JSON: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (No value.) UserInfo=0x7fc3729800d0 {NSDebugDescription=No value.}

As much as i know, as i'm using a VM to run OS X 10.10 and using xCode 6.4, the swift version is 1.2

var url:NSURL?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        url = NSURL (string: "htpp://jsonplaceholder.typicode.com/todos/1")
        let urlRequest = NSURLRequest(URL: self.url!)
        let config = NSURLSessionConfiguration.defaultSessionConfiguration()
        let session = NSURLSession(configuration: config)

        let task = session.dataTaskWithRequest(urlRequest, completionHandler:{(data,response,error) in
            if error == nil{
                print("No error")
            } else{
                print("Error")
            }

            let responseData = data

            var error:NSError? = nil
            if let todo: AnyObject = NSJSONSerialization.JSONObjectWithData(responseData, options: nil, error:&error) as? [String:AnyObject] {
                    print("Info completa")

            } else {
                println("Could not parse JSON: (error!)")
            }

        })

        task.resume()


    }

Anybody can help?

Thanks in advance


Aucun commentaire:

Enregistrer un commentaire