Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – How to fetch complex Json objects in flutter?

Posted on November 14, 2022

Solution 1 :

Try this

var response = jsonDecode(response.body);
List installmentList = List.from(response["installment"]);
setState((){
   _list = installmentList.map((f) => PaymentInstallment.fromJson(f)).toList();
});

If it isn’t looping try this

List tempList = [];
installmentList.forEach((f) => tempList.add(f));
setState((){
  _list = tempList;
});

Problem :

This is the API response I want to fetch “installments” array values

 {
 "unit":
      { 
    .....
      },
 "receipt": 
 {
   .....
 },
"instalments": [
    {
        "payment_type": "5",
        "amount": "3",
        "bank_name": "ABU DHABI COMMERCIAL BANK",
        "paid_date": "2020-08-07 01:11:02",
        "status": "0",
    }
    {
        "payment_type": "5",
        "amount": "3",
        "bank_name": "ABU DHABI COMMERCIAL BANK",
        "paid_date": "2020-08-07 01:11:02",
        "status": "0",
    }
    ]
  }

I use this mode class to get value from API

class PaymentInstallment {
 String payment_type;
 String payment_amount;
 String payment_date;
 String status;

 PaymentInstallment(
     {this.payment_type, this.payment_amount, this.payment_date, this.status});

  factory PaymentInstallment.fromjson(Map<String, dynamic> json) {
    return PaymentInstallment(
    payment_type: json['payment_type'],
    payment_amount: json['amount'],
  payment_date: json['paid_date'],
  status: json['status'],
       );
     }
    }

this is my list and adding the response from the server to it

   List<PaymentInstallment> _list = [];


  final response = await http.get(
    url,
    headers: {"Accept": "application/json", "Authorization": token},
   );
   var response = jsonDecode(response.body);
    setState(() {
    for (Map temppayment in response) {
      _list.add(PaymentInstallment.fromjson(temppayment));
     }
     });

how can i all array value from “instalments” array and add to the list

Comments

Comment posted by Josteve

The fields from the json array “installment” are cleary different from what you have in your PaymentInstallmet class

Comment posted by Marzook

inside there is the value I posted only a few

Comment posted by Krish Bhanushali

response["installments"]

Comment posted by Marzook

thanks , but it’s showing only the first index value on how to loop it?

Comment posted by Josteve

Sorry @Marzook I don’t get your question

Comment posted by Josteve

@Marzook check the other option. I’ve updated my answer

READ  [ANSWERED] ANDROID - How to apply a different theme to a product flavour?
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress