본문 바로가기

iOS/STUDY

[iOS] The data couldn’t be read because it is missing.

테이블 셀에 json 데이터를 가져오던 도중에 발생한 오류

do {
        self.countries = try jsonDecoder.decode([Country].self, from: dataAsset.data)
} catch {
    print("에러나따2")
    print(error.localizedDescription)
}

 

콘솔창에 The data couldn’t be read because it is missing. 

가 떠버렸다.

 

json 데이터를 받아올 구조체를 선언한 파일로 가서

struct Country: Codable {
    let countryName: String
    let assetName: String
    
    enum CodingKeys: String, CodingKey {
        case countryName = "korean_name"
        case assetName = "asset_name"
    }
}

String 변수들의 값이 없다는 뜻이니까 옵셔널 타입으로 바꿔주었는데,

오류는 없어졌지만

테이블에 아무런 정보가 적히질 않았다...

 

 

대략 세시간동안..^^ 구글링했는데 하는말들이 다

오타다 다시 확인해라..  랑

잘못써서 안되는 것밖에 없었다 에효

 

결국

import Foundation

struct Country: Codable {
    
    let korean_name: String?
    let asset_name: String?
    
    /*
    enum Codingkeys: String, CodingKey {
        case koreanName = "korean_name"
        case assetName = "asset_name"
    }
    */
    
}

CodingKeys를 없애고 했더니 하하 ..

되더라..

 

하하..왜안된건데ㅣ..이유가뭔데..

 

똑같은 다른 Codingkeys는 잘만되던데 왜 넌 안되니'

 

 

 

 

 

 

 

 

zㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ

이유는 바로

struct Country: Codable {
    let countryName: String
    let assetName: String
    
    enum CodingKeys: String, CodingKey {
        case countryName = "korean_name"
        case assetName = "asset_name"
    }
}

CodingKeys에서 k가 소문자였던것

블로그 쓰면서 발견했네..^^ 

이걸 3시간동안 찾고있었다니 진짜 괴로웠는데 허무하고 확씨

 

교훈 : 구글링이 하는말은 매우 옳다. 내가 문제 ^_^

'iOS > STUDY' 카테고리의 다른 글

[iOS] Photos  (0) 2021.04.30
[iOS] scrollview autolayout  (0) 2021.03.31
[iOS] segue로 데이터 전달  (0) 2021.03.19
[iOS] UITableView  (0) 2021.03.15
[iOS] Singleton  (3) 2021.03.12