0
返回错误消息:类型'Any'在最后2行代码中没有下标成员。我不能在Swift 3中为NSArray解决这个问题:任何想法?如何将下标成员转换为NSArray Swift 3
let weatherDictionary: NSDictionary = (try! JSONSerialization.jsonObject(with: dataObject!, options: [])) as! NSDictionary
_ = try JSONSerialization.jsonObject(with: dataObject!, options: .allowFragments) as! [String:Any]
然后
struct Weekly{
var dayZeroTemperatureMax: Int
var dayZeroTemperatureMin: Int
init (weatherDictionary: NSDictionary) {
let weeklyWeather = weatherDictionary["daily"] as! NSDictionary
let weeklyForcast = weeklyWeather["data"] as! NSArray
//DAY ZERO
dayZeroTemperatureMax = weeklyForcast[0]["temperatureMax"] as! Int
dayZeroTemperatureMin = weeklyForcast[0]["temperatureMin"] as! Int
}
}
let weatherDictionary:NSDictionary =(try!JSONSerialization.jsonObject(with:dataObject !, options:[]))as! NSDictionary – Bux
让weeklyWeather = Weekly(weatherDictionary:weatherDictionary) – Bux
!! http://json.org/example.html请点击这里。希望你了解什么是JSON! –