0
我有问题试图解析来自JSON的数据。在Swift 2.0中尝试从json解析数据时出现错误?
这是我得到
无法投类型的值的误差 '__NSArrayI'(0x10e7eb8b0)为 'NSDictionary中'(0x10e7ebd60)
let jsonResult: AnyObject?
do {
jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: [])
print(jsonResult, terminator: "");
let channel: NSDictionary! = jsonResult!.valueForKey("CATEGORY_NAME") as! NSDictionary;
print(channel, terminator: "");
let result: NSNumber! = channel.valueForKey("EVENT_NAME") as! NSNumber;
print(result, terminator: "");
if (result == 0)
{
let alertController = UIAlertController(title: "", message: "There is no live stream right now", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
}
catch
{
// TODO: handle
}
}
task.resume()
线我得到的错误是
let channel:NSDictionary! = jsonResult!.valueForKey(“CATEGORY_NAME”) as! NSDictionary的;
很明显,您的JSON包含一个数组,而不是'CATEGORY_NAME'键的字典。 – rmaddy