1
我有来自网站的JSON数据。我做了主要的字典,我可以解析除了一个子字典以外的所有数据。我得到错误“Swift:无法将类型'__NSCFArray'的值转换为'NSDictionary'”Swift:无法将'__NSCFArray'类型的值转换为'NSDictionary'
这是我的数据示例。我无法解析“天气”,但我可以解析所有其他字典,如"wind"
。
["name": Mountain View, "id": 5375480, "weather": (
{
description = "sky is clear";
icon = 01n;
id = 800;
main = Clear;
}
), "base": cmc stations, "wind": {
deg = "129.502";
speed = "1.41";
的片段代表您的评论代码
let windDictionary = mainDictionary["wind"] as! [String : AnyObject
let speed = windDictionary["speed"] as! Double
print(speed)
let weather = mainDictionary["weather"] as! [String : AnyObject]
print(weather)
看来我t是一个数组,而不是字典。尝试 let weather = mainDictionary [“weather”] as? [AnyObject] – dirtydanee
weather is not dictionary ....'let weather = mainDictionary [“weather”] as! [[String:AnyObject]]' –
但是相同语法的风词典 – Alexander