Return json value with php from swift iOS -


hello have small problem code below, xcode print error:

error: json error: error domain=nscocoaerrordomain code=3840 "no value." userinfo={nsdebugdescription=no value.}

swift code:

let yoururl=“mylink.php”     let url = nsurl(string:yoururl)     let request:nsmutableurlrequest = nsmutableurlrequest(url: url!)     let boundaryconstant = "v2ymhfg03esomerandomstuffhbqgzcako6jy";     let contenttype = "multipart/form-data; boundary=" + boundaryconstant     nsurlprotocol.setproperty(contenttype, forkey: "content-type", inrequest: request)     let datastring = "email=\(email.text)&password=\(password.text)"     request.httpmethod = "post"     request.httpbody = (datastring nsstring).datausingencoding(nsutf8stringencoding)     let task = nsurlsession.sharedsession().datataskwithrequest(request, completionhandler: { (data, response, error) -> void in         //reponse recieved         //in case response string saved in data, of type nsdata         do{             let str = try nsjsonserialization.jsonobjectwithdata(data!, options: nsjsonreadingoptions.allowfragments) as! [string:anyobject]             print(str)         }         catch {             print("json error: \(error)")         }       })     task.resume() 

php code:

mylink.php

<?php  header("content-type: application/json");  $email = $_post["email"];  $password = $_post["password"];  $stat=“myvalue”;  return json_encode($stat);  ?> 

how can solve error?


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -