Data.Iteration.Element(aka UInt 8)不能转换为不相关的Type

时间:2016-09-18 05:33:12

标签: json dictionary swift3

我在尝试从互联网上解析来自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'

0 个答案:

没有答案