【问题标题】:Type 'Any' doesn't conform to protocol 'Sequence'类型“任何”不符合协议“序列”
【发布时间】:2016-09-21 15:40:28
【问题描述】:

我的代码有问题,在尝试解析 JSON 数据(数组的每个数据,例如应该如何完成)并尝试设置 for in 循环时,出现错误。这是我的代码

if let jsonDataArray = try? JSONSerialization.jsonObject(with: data!, options: [])
{

    print(jsonDataArray)

    var allStops = [busStops]()

    for eachData in jsonDataArray
                    ^
    //this is where the error is located 

    {

        if let jsonDataDictionary = eachData as? [String : AnyObject]
        {

            let eachStop = busStops(jsonDataDictiony: jsonDataDictionary)

        }

    }

}

【问题讨论】:

    标签: ios arrays swift swift3


    【解决方案1】:

    将jsonDataArray的类型直接指定为[[String: Any]],这样试试。

    if let jsonDataArray = try? JSONSerialization.jsonObject(with: data!, options: []) as? [[String: Any]] {
         for eachData in jsonDataArray {
             let eachStop = busStops(jsonDataDictiony: jsonDataDictionary)
         }
    }
    

    【讨论】:

    • 谢谢,它对我有用。如果让角=barcodeMetadataObject.corners 为? [[字符串:任意]] { }
    猜你喜欢
    • 2017-02-06
    • 2017-06-22
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    相关资源
    最近更新 更多