I am learning swift and I am trying to pass data to ASP using json
This is my code
and I am getting the following error where I am instantiation json(line 43)
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.}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.1.101.15/src/swift/stdlib/public/
import UIKit
class RegisterViewController: UIViewController {
@IBOutlet weak var userEmailTextField: UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
@IBOutlet weak var repeatUserPasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
/
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
/
}
@IBAction func registerButtonTouched(sender: AnyObject) {
let userEmail = userEmailTextField.text;
let userPassword = userPasswordTextField.text;
let userRepeatPassword = repeatUserPasswordTextField.text;
if(userEmail!.isEmpty || userPassword!.isEmpty || userRepeatPassword!.isEmpty)
displayMyAlertMessage("All fields are requred");
return;
if(userPassword != userRepeatPassword)
displayMyAlertMessage("Passwords do not match");
return;
/
let myUrl = NSURL(string: "https:/
let request = NSMutableURLRequest(URL:myUrl!);
if error != nil {
print("error=\(error)")
return
let json = try! NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as? NSDictionary
print("Test")
if let parseJSON = json{
let resultValue = parseJSON["status"] as? String
print("result: \(resultValue)")
var isUserRegistered:Bool = false;
if(resultValue == "Success") {isUserRegistered = true;}
var messageToDisplay:String = parseJSON["message"] as! String;
if(!isUserRegistered)
messageToDisplay = parseJSON["message"] as! String;
let myAlert = UIAlertController(title: "Alert", message: messageToDisplay, preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title:"Ok", style: UIAlertActionStyle.Default){ action in
self.dismissViewControllerAnimated(true, completion: nil);
self.presentViewController(myAlert, animated: true, completion: nil)
func displayMyAlertMessage(userMessage:String)
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
self.presentViewController(myAlert, animated:true, completion:nil);