在這裏我試圖使用移動號碼註冊應用程序,但我不能以正確的格式進行操作,我在Json解析註冊應用程序時出錯。在iOS中快速Json解析如何在post方法中傳遞參數
這裏,我給我所嘗試過的代碼,
var request = NSMutableURLRequest(URL: NSURL(string: "http://app.mycompany.in/gcm/test_slim.php/register")!, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData, timeoutInterval: 5)
var response: NSURLResponse?
var error: NSError?
var reponseError: NSError?
var urlData: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse:&response, error:&reponseError)
// create some JSON data and configure the request
let jsonString = "json=[{\"gsm_number\":\(Mobile),\"name\":\(Name),\"email\":\(Email),\"status\":\(Status),\"ver_code\":,\"profile_picture\":,\"device_id\":,\"gcm\":,\"is_register\":,\"thumb_image\":,\"user_baground_img\":}]"
request.HTTPBody = jsonString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
request.HTTPMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
// send the request
NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: &error)
// look at the response
if let httpResponse = response as? NSHTTPURLResponse {
println("HTTP response: \(httpResponse.statusCode)")
println("jsonString: \(jsonString)")
var responseData:NSString = NSString(data:urlData!, encoding:NSUTF8StringEncoding)!
let VerificationcodeViewController = self.storyboard?.instantiateViewControllerWithIdentifier("verificationcodeViewController") as UIViewController
self.navigationController?.pushViewController(VerificationcodeViewController, animated: true)
} else {
println("No HTTP response")
var alertView:UIAlertView = UIAlertView()
alertView.title = "Error!"
alertView.message = "Error. & Some Problem was Found"
alertView.delegate = self
alertView.addButtonWithTitle("OK")
alertView.show()
}
你可以在這裏發佈相關的錯誤? – Bannings
請提及錯誤。 –
語法錯誤發生 –