I have this line of code and I want to extract the "title" key:
var title = jParams["title"] as! String
However, it will not allow me to compile, and if I get this error message in red:
You cannot index a value of type AnyObject with an index of type String
When you display the contents of jParams in a log using println(jParams) , I get the following content:
INCOMING LIST PARAMETERS (jParameters) Optional({ title = "Example List"; values = ( { id = 1; name = "Line 1"; }, { id = 2; name = "Line 2"; }, { id = 3; name = "Line 3"; } ); })
I am new to Swift, so I am not familiar with the details of JSON processing to solve these problems. What could be wrong?
//jParams comes from a JSON server response var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: nil, error: nil) if data != nil { var jdata = JSON(data: data!) var jParams=jdata["responseData"]["extraData"]["params"]
source share