无法将“__NSArrayM”类型的值转换为“NSDictionary” [英] Could not cast value of type '__NSArrayM' to 'NSDictionary'
本文介绍了无法将“__NSArrayM”类型的值转换为“NSDictionary”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个json。我正在尝试使用该代码解析它。但是它说
I have a json.I am trying to parse that with that code.But its says
无法转换类型的值' __NSArrayM'到'NSDictionary'
Could not cast value of type '__NSArrayM' to 'NSDictionary'
do {
let dataDictionary: NSDictionary = try NSJSONSerialization.JSONObjectWithData(responseObject as! NSData, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary // <------ Error
if let customerArray = dataDictionary.valueForKey("cart") as? NSArray {
for js in customerArray {
let nameArray = js.valueForKey("name")
let idArray = js.valueForKey("id")
}
}
}
感谢您的帮助
推荐答案
数据中的根对象是一个数组,而不是一个对象(字典)。
The root object in your data is an array, not a object (dictionary).
你需要根据反序列化的对象动态决定如何处理JSON。
You need to dynamically decide how to handle your JSON depending on the deserialized object.
这篇关于无法将“__NSArrayM”类型的值转换为“NSDictionary”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文