I am trying to access each title in a returned json. This is the JSON
[
"Hyouka",
"Youjo Senki",
"Bungou Stray Dogs 2nd Season",
"Fullmetal Alchemist: Brotherhood",
"Tokyo Ghoul √A",
"Mahouka Koukou no Rettousei",
"Boku wa Tomodachi ga Sukunai NEXT",
"Joker Game",
"Avatar: The Last Airbender",
"Charlotte"
]
It’s just a bunch of values and no key for me to construct my model object. This is how I would plan to do it
struct AllNames {
let name: String
}
But there’s no key name for me to access. How would you go about accessing this data to print each name to the console in Swift?
2
Answers
Your json is an array of strings , so no model is here and you only need
Convert JSON string to array:
Test case:
Print log: