php - Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." in Swift 3 -


i'm working on project , below swift code. when run error.

error domain=nscocoaerrordomain code=3840 "json text did not start array or object , option allow fragments not set." userinfo={nsdebugdescription=json text did not start array or object , option allow fragments not set.}

also check response database says has valid content length. because of error cannot want.

from response print in code;

optional(<nshttpurlresponse: 0x608000233bc0> { url: http://192.168.1.99/insertdata.php } { status code: 200, headers {     connection = "keep-alive";     "content-length" = 10;     "content-type" = "text/html; charset=utf-8";     date = "wed, 13 sep 2017 21:37:38 gmt";     "keep-alive" = "timeout=5, max=100";     server = "apache/2.4.10 (raspbian)"; } })` 

this code.

let urlofsmartcf = url(string: "http://192.168.1.99/insertdata.php") let request = nsmutableurlrequest(url: urlofsmartcf! url)   request.httpmethod="post" request.addvalue("application/json", forhttpheaderfield: "content-type") request.addvalue("application/json", forhttpheaderfield: "accept")  contact in contactscaptuure {     let usermobilenumber = dbmanager.shared.retriveregisterednumberofmobile()         let postparameters = "\"usermobilenum\":\(string(describing: usermobilenumber!)),\"contactnum\":\(contact.phonenumber!)";     request.httpbody = postparameters.data(using: string.encoding.utf8)     let task = urlsession.shared.datatask(with: request urlrequest)     {         data, response, error in          if error != nil         {             print("error \(string(describing: error))")             return;         }                 {             print(response)             let myjson = try  jsonserialization.jsonobject(with: data!, options: .mutablecontainers) as? nsdictionary             if let parsejson = myjson             {                 var msg : string!                 msg = parsejson["message"] as! string?                 print(msg)              }         }         catch         {             print(error.localizeddescription)             print(error)         }      }     print("done")     task.resume() } 

so complete project need solve this.please help. thank you.

sam response

echo ('{"response":[{"status":"fail"}]}'); or

echo ('{"response":[{"status":"success"},{"userid":'.$userid.'}]}');

try , let know please... :)


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -