Mock JSON 오류 확인하기
JSON validation check
JSON
Mock.json Validation Check
guard let path = Bundle.main.path(forResource: "mock", ofType: "json") else {
return
}
print(path)
guard let jsonString = try? String(contentsOfFile: path) else {
return
}
print("jsonString: \(jsonString)")
let data = jsonString.data(using: .utf8)
if let data = data {
do {
var tins = try JSONDecoder().decode([Tinowledge].self, from: data)
print("tins: \(tins.first?.content)")
for i in tins.indices {
tins[i].id = UUID().uuidString
tins[i].createdAt = "\(Date())"
vStore.send(.addTin(tins[i]))
}
print("tins id: \(tins.first?.id)")
// print("tin: \(tins.content)")
} catch DecodingError.keyNotFound(let key, let context) {
Swift.print("could not find key \(key) in JSON: \(context.debugDescription)")
} catch DecodingError.valueNotFound(let type, let context) {
Swift.print("could not find type \(type) in JSON: \(context.debugDescription)")
} catch DecodingError.typeMismatch(let type, let context) {
Swift.print("type mismatch for type \(type) in JSON: \(context.debugDescription)")
} catch DecodingError.dataCorrupted(let context) {
Swift.print("data found to be corrupted in JSON: \(context.debugDescription)")
} catch let error as NSError {
NSLog("Error in read(from:ofType:) domain= \(error.domain), description= \(error.localizedDescription)")
}
return
}