1.项目原因获取到Socket后台传过来的JSon字符串
获取后为 Any 类型
let string = message as! String
let data = string.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
let jsonDic = try? JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String : Any]
2.获取网络请求后的JSon
if JSONSerialization.isValidJSONObject(responseObject!) {
let jsonData = try? JSONSerialization.data(withJSONObject: responseObject!, options: JSONSerialization.WritingOptions.prettyPrinted)
let jsdonDic = try? JSONSerialization.jsonObject(with: jsonData!, options: JSONSerialization.ReadingOptions.mutableContainers)
success(jsdonDic as! Dictionary<String, Any>)
}
网友评论