私はswift2.2用のjson構文解析コードを使用していますが、Swift 3.0用に使用するとエラーが発生します(タイプ'Any'には添字のメンバーはありません)。コード。タイプ'Any 'には添え字がありません
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers)
if json is [String: AnyObject] {
print(json)
if let error = json["error"] as? String {
print(error);
} else if let items = json["items"] as? [[String: AnyObject]] {
for item in items {
print(item)
let book_id = item["id"] as? String
if let volumeInfo = item["volumeInfo"] as? [String: AnyObject] {
let book_title = volumeInfo["title"] as? String
DispatchQueue.main.async(execute: {() -> Void in
self.lblDataInfo.text = "ISBN: "+self.currentISBN!+" ID:"+book_id!
self.lblDataType.text = book_title
})
}
break // for now, only show first
}
} else {
DispatchQueue.main.async(execute: {() -> Void in
self.lblDataInfo.text = "ISBN: "+self.currentISBN!+" Not identified"
self.lblDataType.text = ""
})
}
}
} catch let jsonError {
print(jsonError)
}
}
task.resume()
}
}
** Related **の欄には多くの関連する質問があります。 – vadian