All the examples I find are using dictionary types, for example: user: x, book: y
but how can I convert this type of Json which doesn't contain a key?
["1","137","56","56"]
This is of type String?
I tried:
struct Candidate: Decodable {
var S: String?
}
let chainsAllowed = ["1","137","56","56"]
let jsonObjectData = chainsAllowed.data(using: .utf8)!
let candidate = try? JSONDecoder().decode(
Candidate.self,
from: jsonObjectData
)
but I get nil. How can I convert it into an array?
Thanks
try?is literally saying "If there are any errors, please disregard them and just give menil". If you caught the error instead and took a look at it, you would have gotten a useful error message.false / null / true / object / array / number / string. See datatracker.ietf.org/doc/html/rfc8259#section-2AWSJSON