我正在尝试在 Swift 中提交 JSON-RPC 请求,并且我正在遵循此(在 iOS Swift 中执行 POST 请求)指南。
不幸的是,我无法通过这样做将答案的“结果”部分转换为 NSDictionary:
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)")
}
}
其中 responseObject 是 AnyObject。
我的响应对象如下所示:
{
id = 1;
jsonrpc = "2.0";
result = "[{\"ID\":11,\"Name\":\"MyName\",\"LLogon\":\"2015-03-16T13:04:14\"}]";}