0
我試圖從json結果中獲取信息並追加和訪問某些鍵值。不過,我得到錯誤「類型‘[字符串:任何]’已經沒有下成員類型'[String:Any]'在Swift中沒有下標成員
let json = try? JSONSerialization.jsonObject(with: data!, options: []) as! [String: Any]
for case let studentsInfo in json["results"] {
if let studentInfo = StudentResults(json: result) {
let name = firstName + " " + lastName
StudentsResults.append(name)
}
這也是我一直放置在延伸結構
struct StudentResults{
let firstName: String
let lastName: String
let latitude: Double
let longitude: Double
let mapString:String
let mediaURL: String
let objectID:String
let uniqueKey: String
let updatedAt: String
}
convenience init?(json: [String: Any]) {
guard let firstName = json["firstName"] as? String,
let lastName = json["lastName"] as? String
else {
return nil
}
return nil
這是。我也爲這個項目GitHub的頁面,如果你想看看它
https://github.com/SteveBurgos95/UdacityMapProject
我試圖這樣做,但我得到的,說:「初始值設定條件綁定錯誤必須有可選類型,而不是'[String:Any]'「如果我將它改爲可選,那麼我得到Tye Any?不符合協議順序。 @InfinityJames –