0

I'm trying to submit a JSON-RPC request in Swift and I was following this ( Perform POST request in iOS Swift ) guide.

Unfortunately I'm not able to cast the "result" part of the answer to NSDictionary by doing this:

if let responseDictionary = responseObject as? NSDictionary {
    if let errorDictionary = responseDictionary["error"] as? NSDictionary {
        println("error logging in (bad userid/password?): \(errorDictionary)")
    } else if let resultDictionary = responseDictionary["result"] as? NSDictionary {
        println("successfully logged in, refer to resultDictionary for details: \(resultDictionary)")
    } else {
        println("we should never get here")
        println("responseObject = \(responseObject)")
    }
}

where responseObject is AnyObject.

My response object looks like this:

{
id = 1;
jsonrpc = "2.0";
result = "[{\"ID\":11,\"Name\":\"MyName\",\"LLogon\":\"2015-03-16T13:04:14\"}]";}
Community
  • 1
  • 1
Azulath
  • 126
  • 1
  • 7
  • "result" isn't a dictionary, it's a string. – Hot Licks Mar 18 '15 at 19:18
  • As Hot Licks said, the value of the "result" key is a string. This string is the JSON representation of a dictionary. If possible, fix the server to send a proper response. Otherwise you have to deserialize twice (see http://stackoverflow.com/questions/17283141/cannot-parsing-json-to-nsdictionary for a similar issue). – Martin R Mar 18 '15 at 19:25
  • We heard you like JSON – Nate Cook Mar 18 '15 at 19:28

1 Answers1

0

As Hot Licks and Martin R pointed out this was indeed a server side issue.

Azulath
  • 126
  • 1
  • 7