我想在字典中发布数据。首先让我展示一下我在做什么。
manager.POST(url, parameters: dict,
success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in
if let jsonDict = self.parseJSON(responseObject) {
print(jsonDict)
// Error occur on the following line
let dataDict = jsonDict["data"] as! [String : AnyObject]
// Error Info: Swift: Could not cast value of type 'Could not cast value of type '__NSCFString' (0x10e4d5ef0) to 'NSDictionary' (0x10e4d6bc0).'
}

func parseJSON(inputData: AnyObject) -> Dictionary<String,AnyObject>?{
do {
let jsonDict = try NSJSONSerialization.JSONObjectWithData(inputData as! NSData, options:NSJSONReadingOptions.MutableContainers) as! Dictionary<String,AnyObject>
// use jsonData
return jsonDict
} catch let error as NSError {
// report error
print(error.description)
print("Session: Json Parse Error!!!")
return nil
}
}
&#13;
这是pirnt(jsonDict)
的结果[data:{&#34; session_id&#34;:&#34; ab4kn9fj34ko89kjkl5ljs98gfk498fgkl409alk34l&#34;,&#34; user_info&#34;:{&#34; username&#34;:&#34; Johny Cage& #34;,&#34; ENCPASSWORD&#34;:&#34; johnycage&#34;,&#34; id&#34;:1,&#34; FULLNAME&#34;:&#34; Johny Cage&#34 ;}},状态:成功]
非常感谢任何帮助或建议。
答案 0 :(得分:1)
检查来自网络服务的返回数据。我想你是多次用Jason String转换它,或者类似的东西。上面的代码没有问题。检查服务器端。