gpt4 book ai didi

ios - 类型 'Any' 不符合协议(protocol) 'Sequence'

转载 作者:搜寻专家 更新时间:2023-10-31 22:13:00 25 4
gpt4 key购买 nike

我在我的代码中遇到了问题,在尝试解析 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)

}

}

}

最佳答案

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

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

关于ios - 类型 'Any' 不符合协议(protocol) 'Sequence',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39621023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com