【问题标题】:Swift: Could not cast value of type 'Could not cast value of type '__NSCFString' (0x10e4d5ef0) to 'NSDictionary' (0x10e4d6bc0).'斯威夫特:无法将“无法将“__NSCFString”(0x10e4d5ef0)类型的值转换为“NSDictionary”(0x10e4d6bc0)类型的值。
【发布时间】:2017-07-19 07:24:37
【问题描述】:

我正在尝试在字典中获取帖子数据。首先让我展示一下我在做什么。

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).'

}
ParseJson 函数:
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
        }
    }

这是 pirnt(jsonDict) 的结果

[数据:{"session_id":"ab4kn9fj34ko89kjkl5ljs98gfk498fgkl409alk34l","user_info":{"用户名":"Johny Cage","ENCPASSWORD":"johnycage","id":1,"FULLNAME":"Johny Cage "}},状态:成功]

非常感谢任何帮助或建议。

【问题讨论】:

标签: swift2


【解决方案1】:

从网络服务检查您的退货数据。我认为您在 Jason String 中多次转换它,或者类似的东西。上面的代码没有问题。检查您的服务器端。

【讨论】:

  • 谢谢您,先生,这是您第二次拯救我的一天。是的,正如你提到的,我的客户端有一些额外的东西。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2017-04-15
  • 2017-07-01
  • 2020-08-23
  • 2015-10-26
  • 2016-08-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多