發(fā)出POST請(qǐng)求時(shí),Xcode調(diào)試器顯示錯(cuò)誤錯(cuò)誤域= NSCocoaErrorDomain代碼= 3840“ JSON文本不是以數(shù)組或?qū)ο箝_頭,并且沒有允許設(shè)置片段的選項(xiàng)?!?UserInfo = {NSDebugDescription = JSON文本不是以數(shù)組或?qū)ο箝_頭,并且未設(shè)置允許片段的選項(xiàng)。}這是POST函數(shù), func startArchive() { let app_Id = (appId.base64Decoded()!) let job_Id = (jobId.base64Decoded()!) var response_ = 0 guard let url = URL(string: "https://xxx.yyyy.com/question/abc") else {return} let request = NSMutableURLRequest(url:url) request.httpMethod = "POST" let postString = "session_id=\(pSessionId)&job_id=\(job_Id)&app_id=\(app_Id)&action=start" print(postString) request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type") request.httpBody = postString.data(using: String.Encoding.utf8) let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in guard error == nil && data != nil else { // check for fundamental networking error print("error=\(String(describing: error))") return } do { if let responseJSON = try JSONSerialization.jsonObject(with: data!) as? [String:AnyObject]{ print(responseJSON) print(responseJSON["status"]!) response_ = responseJSON["status"]! as! Int print(response_) //Check response from the sever if response_ == 200 { OperationQueue.main.addOperation { print("Login Successful") } }
“ JSON文本不是以數(shù)組或?qū)ο箝_頭,并且沒有允許設(shè)置片段的選項(xiàng)。”
桃花長(zhǎng)相依
2021-05-05 17:25:09