Home > Enterprise >  How the model class will be design to fetch the nested array object in recycler view?
How the model class will be design to fetch the nested array object in recycler view?

Time:02-03

I am using a free IMDB api for Json practicing , but don't know how to fetch these data through recycler view. Here is the Json api data which I need to fetch.

{
    "technical_specs": [
        [
            "Runtime",
            "2 hr 28 min (148 min)"
        ],
        [
            "Sound Mix",
            "Dolby Digital | DTS | SDDS"
        ],
        [
            "Color",
            "Color"
        ],
        [
            "Aspect Ratio",
            "2.39 : 1"
        ],
        [
            "Camera",
            "Arriflex 235, "
        ],
        [
            "Laboratory",
            "Imagica Corporation, Shinagawa-ku, "
        ],
        [
            "Film Length",
            "3,925 m (Portugal) <br> 4,037 m (Sweden)"
        ],
        [
            "Negative Format",
            "35 mm (also horizontal) (Kodak Vision3 250D 5207, Vision3 500T 5219) <br> 65 mm (Kodak Vision3 250D 5207, Vision3 500T 5219)"
        ],
        [
            "Cinematographic Process",
            "Panavision (anamorphic) <br> Panavision Super 70 (some scenes) <br> VistaVision (aerial shots)"
        ],
        [
            "Printed Film Format",
            "35 mm (Kodak Vision 2383) <br> 70 mm (horizontal) (IMAX DMR blow-up) (Kodak Vision 2383) <br> D-Cinema"
        ]
    ]

}

I got confused to make a proper model for nested array

CodePudding user response:

In this JSON response , assuming the "technical_specs" as not fixed key, if you are using Retrofit to fetch the data, the method will be as follows,

fun fetchData(): Response<HashMap<String, List<List<String>>>>

and then you can use this hashmap to populate your recycler view, you dont need to create any Pojo class for this.

  •  Tags:  
  • Related