我在尝试从互联网上解析来自API的JSON数据时遇到问题
if let jsonDataArray = try? JSONSerialization.data(withJSONObject: data, options: [])
{
print(jsonDataArray)
var allStops = [busStops]()
for eachData in jsonDataArray (this is where the Type 'Any' error is)
{
if let jsonDataDictionary = eachData as? [String : AnyObject]
{
let eachStop = busStops(jsonDataDictiony: jsonDataDictionary)
}
}
}
我收到此错误(eachData无法转换为[String:AnyObject]
Cast from 'Data.Iterator.Element' (aka 'UInt8') to unrelated type '[String : AnyObject]' always fails
编辑:使用JSONSerialization.WithObject(...)更改了JSONSerialization.data(...),如上所述,并抛出错误
Type 'Any' doesn't conform to protocol 'Sequence'