解析JSON&错误

时间:2016-09-25 16:20:34

标签: json database swift

对我来说它不起作用。我收到一个错误:

  

错误域= NSCocoaErrorDomain代码= 3840"没有值。"   UserInfo = {NSDebugDescription =无值。}

它永远不会进入if循环,我无法理解为什么。我是swift的初学者,但看起来代码很好。

    do
{
    //I am never entering that loop.... and I receive the message in the bottom of the screen
    if let parseJSON = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary
    {
        print(parseJSON["status"])

        let resultValue = parseJSON["status"] as? String
        print("result\(resultValue)")

        var isUserRegsitered:Bool = false;
        if(resultValue=="Success") { isUserRegsitered = true; }

        var messageToDisplay:String = parseJSON["message"] as! String!;
        if (!isUserRegsitered)
        {
            messageToDisplay = parseJSON["message"] as! String!;
        }

        dispatch_async(dispatch_get_main_queue(),
                       {
                        //display alert message with confirmation
                        var myAlert = UIAlertController(title:"Alert", message:messageToDisplay, preferredStyle: UIAlertControllerStyle.Alert);
                        let okAction = UIAlertAction(title:"Ok", style: UIAlertActionStyle.Default)
                        {
                            action in self.dismissViewControllerAnimated(true, completion: nil);

                        }

                        myAlert.addAction(okAction);
                        self.presentViewController(myAlert, animated: true, completion: nil);

        } );
        //end if

    }
}
catch let error as NSError
{
    print(error)
}

0 个答案:

没有答案