I just tried this:
let test = "{ \"de\": \"Bisasam\", \"en\": \"Bulbasaur\" }"
let data = test.data(using: .utf8)!
do {
let result = try JSONDecoder().decode([String: String].self, from: data)
print("") // breakpoint here works
} catch {
print("")
}
This works fine, however when I try to do this instead:
enum Lg: String, CaseIterable, Decodable {
case deutsch = "de"
case english = "en"
}
let test = "{ \"de\": \"Bisasam\", \"en\": \"Bulbasaur\" }"
let data = test.data(using: .utf8)!
do {
let result = try JSONDecoder().decode([Lg: String].self, from: data)
print("")
} catch {
print("") // breakpoint here
}
With this error:
▿ DecodingError ▿ typeMismatch : 2 elements
- .0 : Swift.Array ▿ .1 : Context
- codingPath : 0 elements
- debugDescription : "Expected to decode Array but found a dictionary instead."
- underlyingError : nil
What am I doing wrong?
Thanks for your help