我想访问另一个json内的Json的一些数据
这是我的代码:
let extraData = userInfo["extraData"] as! [String : Any]
print(extraData["message_id"])
但运行时出现以下错误:
Could not cast value of type '__NSCFString' (0x264300f90) to 'NSDictionary' (0x264301bc0)
这是我的杰森:
[AnyHashable(“ largeIcon”):http://test.png,AnyHashable(“ notifyType”):notifyData,AnyHashable(“ ledColor”):#f39c12,AnyHashable(“ extraData”):{“ is_background”:0, “ message_id”:“ 1156”,“ deep_link”:{“ action_type”:“ U”,“ url”:“ teknik:// teknik”}},AnyHashable(“ message”):test,AnyHashable(“ id”) :50368138,AnyHashable(“ vibrate”):1,AnyHashable(“ gcm.message_id”):0:1544436390847%bebba17fbebba17f,AnyHashable(“ autoRun”):false,AnyHashable(“ action”):{“ type”:“ A “,” url“:” Activity.MessageActivityJava“},AnyHashable(” sound“):3,AnyHashable(” title“):newtest,AnyHashable(” aps“):{ “内容可用” = 1; }]
答案 0 :(得分:0)
您可以尝试
do {
let dd = userInfo["extraData"] as! String
let con = try JSONSerialization.jsonObject(with: dd.data(using: .utf8)!, options: []) as! [String:Any]
print(con["message_id"])
catch {
print(error)
}
作为extraData
的值是一个json字符串,而不是直接字典