0
我期待將嵌套在數組中的字典強制轉換爲AnyObject變量。例如,我在我的函數中聲明變量:將AnyObject投射到嵌套在數組中的字典
var items: [[String:String]] = [
[
"pid": "1",
"content": "123",
"vote": "1",
"city": "New York",
"country": "United States"
]
]
然後,我從HTTP請求中獲取JSON對象並將其轉換爲AnyObject。然後,我試圖將HTTP請求獲取的數據作爲AnyObject附加到原始變量上。
此過程在將AnyObject強制轉換爲所需的[[String:String]]窗體時失敗。
func updateTable(data: AnyObject?) {
let data_array = (data as! NSArray) as! Array<Dictionary<String, String>>
self.items += data_array
}
此功能包括投射變量和添加數組。
我該如何正確投射這個變量?
編輯 我忘了提,我投我的序列化JSON輸出[AnyObject]使其通過功能
試試這個=>讓data_array中=數據! NSDictionary –
它與原始變量不兼容是[[String:String]] –
試試這個=>數據作爲Dictionary –