그래서 서버에서 일부 json 데이터를 받으면 배열로 저장하려고하므로 tableview를 채울 수 있지만 문제가 발생했습니다. 내 코드 :구문 분석 된 json 데이터를 신속하게 배열에 저장하는 방법
class UserInfo : UIViewController{
var main = ""
session.dataTask(with: url) { (data, response, error) in
if let response = response {
print (response)
}
if let data = data {
let json = (try? JSONSerialization.jsonObject(with: data, options: []))
print(json)
guard let array = json as? [Any] else {return}
for info in array {
guard let infoDict = info as? [String : Any] else{return}
//there is a declared var called main
//main is the one i want save as an array, currently its a variable. i tried to save it as an array by using as! Array but i get error
self.main = infoDict["Title"] as! String
print (self.main)
}
}
}.resume()
}
수신 한 json을 게시해야 Google에서 어떤 데이터를 처리하는지 알 수 있습니다. – ovidiur
"하지만 오류가 발생합니다."어떤 오류가 있습니까? – Larme
이러한 데이터를 UserDefaults에 저장 하시겠습니까? – shahnilay86