所以我试图用swift解析JSON中的一些数据。下面是我的代码Swift中的NSDictionary:无法下标'AnyObject'类型的值与'Int'类型的索引
var jsonResult:NSDictionary! = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary
println(jsonResult)
上面的代码将返回这样的事情
{
count = 100
subjects = (
{
alt = "....."
name = "....."
},
{
alt = "....."
name = "....."
},
......
)
}
后来我尝试访问所有的受试者jsonResult["subjects"]
,到目前为止好 但是,当我尝试访问个人主题,例如jsonResult["subjects"][0]
,Xcode给我错误: Cannot subscript a value of type 'AnyObject?' with an index of type 'Int'
有人可以帮助我吗?
谢谢,完全正常 – JSNoob