0
JSONを使用してiOSでWebサービスを使用しようとしましたが、最後に上記のエラーが発生します。それは起こって..オプション(<OS_dispatch_data:data [0x7f97b145f2f0] = {leaf、size = 17290、buf = 0x11a63f000}>)
JSONを使用してiOSでWebサービスを使用しようとしましたが、最後に上記のエラーが発生します。それは起こって..オプション(<OS_dispatch_data:data [0x7f97b145f2f0] = {leaf、size = 17290、buf = 0x11a63f000}>)
があなたのDOとキャッチを修正してみ..
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) {
}
}
単なる文字列
へのNSDataを変換する//NSString *String = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"responseObject:%@",String);