Maan Maan - 1 month ago 28
JSON Question

Optional(<OS_dispatch_data: data[0x7f97b145f2f0] = { leaf, size = 17290, buf = 0x11a63f000 }>)

Trying to consume web service in iOS using JSON but end up with the above error in the last.. not sure why that's happening..

Answer

Try correcting your do and catch..

import UIKit

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    @IBOutlet weak var lbl_studentID: UILabel!
    @IBOutlet weak var image: UIImageView!

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

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func btnfunc_getStudentID(sender: UIButton) {

        let data:String = "http://neo4j.nannasgroup.com/service.php"
        let url:NSURL = NSURL.init(string: data)!
        let req:NSURLRequest = NSURLRequest.init(URL: url)
        let res:AutoreleasingUnsafeMutablePointer<NSURLResponse?>=nil

        do {
            let dataVal = try NSURLConnection.sendSynchronousRequest(req, returningResponse: res)

            do {
                if let jsonResult = try NSJSONSerialization.JSONObjectWithData(dataVal, options: []) as? NSMutableArray {
                    lbl_studentID.text = "\(jsonResult)"
                }
            } catch let error as NSError {
                print(error.localizedDescription)
            }
        } catch let error as NSError {
            print("incatch" + error.localizedDescription)
        }

    }

    @IBAction func selectPicture(sender: UIButton) {

        let ImagePicker = UIImagePickerController()
        ImagePicker.delegate = self
        ImagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary

        self.presentViewController(ImagePicker, animated: true, completion: nil)
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

        image.image = info[UIImagePickerControllerOriginalImage] as? UIImage
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    @IBAction func upload_request(sender: UIButton) {
      }
}