gpt4 book ai didi

json - 处理Swift 2.0 Google Maps Json时出错

转载 作者:行者123 更新时间:2023-12-03 09:06:37 26 4
gpt4 key购买 nike

我想对从Google map 收到的JSON进行错误处理,
问题是我已经在Swift 1.2中编写了它,但是当我迁移到Swift 2.0和XCode 7 Beta时,问题出现了,
这是代码Swift 1.2:

  var error: NSError?

let dictionary: Dictionary<NSObject, AnyObject> = NSJSONSerialization.JSONObjectWithData(geocodingResultsData!, options: NSJSONReadingOptions.MutableContainers, error: &localError) as! Dictionary<NSObject, AnyObject>

最佳答案

在Swift 2.0中,需要捕获...

do {
let dictionary = try NSJSONSerialization.JSONObjectWithData(geocodingResultsData, options: NSJSONReadingOptions.MutableContainers) as? NSDictionary
} catch let error as NSError {
print(error)
}

可能需要进行一些更改...但这是您在Swift 2.0中要做的方法

关于json - 处理Swift 2.0 Google Maps Json时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32961452/

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