Getting informations from db with php script & swift code

as i said in the title, i want to get informations from a database, using php script & swift code. The program stops at the very last line i’ve just shown you. I’ve got this error message “nalytics Code –>
fatal error: ‘try!’ expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=3840 “JSON text did not start with array or object and option to allow fragments not set.” UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.” I need help 🙂

            let post:NSString = "email=\(username)&password=\(password)"

            NSLog("PostData: %@",post);

            let url:NSURL = NSURL(string: "")!

            let postData:NSData = post.dataUsingEncoding(NSASCIIStringEncoding)!

            let postLength:NSString = String( postData.length )

            let request:NSMutableURLRequest = NSMutableURLRequest(URL: url)
            request.HTTPMethod = "POST"
            request.HTTPBody = postData
            request.setValue(postLength as String, forHTTPHeaderField: "Content-Length")
            request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
            request.setValue("application/json", forHTTPHeaderField: "Accept")

            var reponseError: NSError?
            var response: NSURLResponse?

            let urlData: NSData? = try! NSURLConnection.sendSynchronousRequest(request, returningResponse:&response)

            if ( urlData != nil ) {
                let res = response as! NSHTTPURLResponse!;

                NSLog("Response code: %ld", res.statusCode);

                if (res.statusCode >= 200 && res.statusCode < 300)
                    let responseData:NSString  = NSString(data:urlData!, encoding:NSUTF8StringEncoding)!

                    NSLog("Response ==> %@", responseData);

                    let error: NSError?

                    let jsonData = try! NSJSONSerialization.JSONObjectWithData(urlData!, options: NSJSONReadingOptions.MutableContainers) as! NSArray

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s