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