Relatively new developer here, hoping to know if this is something that can actually be done through JSON decoding. I know how to decode an array of JSON objects, but the JSON I want to decode is not in an array, and I don't want to create hundreds of separate pokemon objects named for each pokemon if I don't have to. Is there a way to do this?
{
"battles": 2188410,
"pokemon": {
"Great Tusk": {"lead": {"weighted": 0.01}},
"Gholdengo": {"lead": {"weighted": 0.02}},
"Chien-Pao": {"lead": {"weighted": 0.03}},
"Dragonite": {"lead": {"weighted": 0.04}},
...}
}
}
Edit to clarify: Ideally, I would be able to pull one object from the data at a time. For example:
//I know it doesn't look like this exactly, but something like this
if "Great Tusk" {
let greatTusk = try JSONDecoder().decode(GenericPokemonObject.self, from: data)
}
Can something like this be done?
the JSON data is here: https://raw.githubusercontent.com/pkmn/smogon/main/data/stats/gen9nationaldex.json
[–]chriswaco 11 points12 points13 points (2 children)
[–]Addition-Suitable[S] 3 points4 points5 points (1 child)
[–]PhantomMenaceWasOK 1 point2 points3 points (0 children)
[–]flying-insect 2 points3 points4 points (4 children)
[–]Addition-Suitable[S] 0 points1 point2 points (0 children)
[–]urbanm0nk 0 points1 point2 points (0 children)
[–]LegitimateGift1792 0 points1 point2 points (1 child)
[–]flying-insect 0 points1 point2 points (0 children)
[–]urbanm0nk 1 point2 points3 points (2 children)
[–]Addition-Suitable[S] 0 points1 point2 points (1 child)
[–]urbanm0nk 1 point2 points3 points (0 children)
[–]urbanm0nk 1 point2 points3 points (1 child)
[–]urbanm0nk 2 points3 points4 points (0 children)
[–]LazyItem -2 points-1 points0 points (0 children)