swift3 - The error is "Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.}" -


i'm learning json. have problem parsing json url. error :

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

json valid - i've checked. structure of json:

and code:

import uikit  @ibaction func signintapped(_ sender: uibutton) {     if validate() == true     {         let myurl = url(string: "")         var myrequest = urlrequest(url: myurl!)         myrequest.httpmethod = "post"         myrequest.addvalue("application/json", forhttpheaderfield: "content-type")          let poststring = "{\"login_username\":\"xyz\",\"login_password\":\"abc\"}"         myrequest.httpbody = (poststring string).data(using: .utf8)         urlsession.shared.datatask(with: myrequest, completionhandler: { (data:data?, response:urlresponse?, error:error?) -> void in             if error != nil             {                 print("fail")                 return             }              //print response object             print("*************response = \(response)")              //print response body             let responsestring = string(data: data!, encoding: string.encoding.utf8)             print("**************response data \(responsestring)")              {                 let json = try jsonserialization.jsonobject(with: data!, options: .mutablecontainers) as? nsdictionary                 print ("1")                  if let parsejson = json {                      let username = parsejson["login_username"] as? string                     print ("2")                     if( username != nil) {                      }                     else                     {                         let errormessage = parsejson["message"] as? string                         print ("3")                     }                 }             }             catch             {                 print(error)             }         }).resume()     } } 


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -