我的工作我的IOS10的應用程序的兼容性,我有一個問題,當執行這段代碼:IOS 10 objectForKey(「鑰匙」)的兼容性
if let results = NSJSONSerialization.TryJSONObjectWithData(data, options: []) as? NSDictionary {
print(" results : \(results)");
if let networkPosts = results["results"] as? NSMutableArray {
print(" here");
for i in 0 ..< networkPosts.count {
let post:Post = Post(postDictionary: networkPosts[i] as! NSDictionary, context: (UIApplication.sharedApplication().delegate as!
AppDelegate).coreDataHelper.managedObjectContext);
}
}
}
我可以看到結果,因此JSON是確定的,但在我看不到字典的結果鍵之後。 「Here」永遠不會打印在我的控制檯上。我試着做出一個斷點,但它並沒有通過那裏。 我也試過.objectForKey("key")
但結果相同:/
有人可以幫我嗎?
如果我使用results["results"] as? [[String: Any]]
然後
networkPosts [I]作爲! NSDictionary中總是失敗
後的JSON您收到 –
請向我們展示您的json響應。 –
你的json中有'results'鍵嗎?或者它是'結果'? – Santosh