Extract info from JSON question?

Hi everyone,

I got some question in my project here.

Let’s say this is my JSON files data, is an array of car’s brand and each of their model,

“brand”: “AUDI”,
“model”: [“A3”, “A4”, “A5”]
“brand”: “BMW”,
“model”: [“1 SERIES”,“2 SERIES”,“3 SERIES”]
“brand”: “MERCEDES BENZ”,
“model”: [“A CLASS”,“B CLASS”,“C CLASS”]

When I extract this JSON data for the brand in my picker, I do like this

by using the carMake.swift here

carMake[row].brand is to extract my brand right?

This is the outcome of the carMake[row].brand

How do I extract the brand’s model? such as in brand “AUDI” there are model “A3” , “A4” and etc?

Do I need another empty array to store the model array?
I don’t know if my question make any sense. :expressionless:

make sure you “row” is saved globally (like selectedCarIndex)
then use that to get the model simply
carMake[selectedCarIndex].model[modelSelected] (its a two dimensional array so the logic is a bit different)

1 Like

Thanks a lot Francis! I now get the idea. I’ll try to look it up. Thanks for the help again.

1 Like