0

I am getting json response from server as below.

[
    [{
        "ID": 1,
        "Date": "11-09-2015",
        "Balance": 1496693.00
    }, {
        "ID": 2,
        "Date": "01-10-2015",
        "Balance": 1496693.00
    }],
    [{
        "ID": 1,
        "Date": "03-09-2000",
        "IntAmount": "003.00"

    }],
    [{
        "EmployeeId": "000",
        "DesignationName": "deg"

    }],
    [{
        "LoanAmount": "00000.00",
        "IntRate": "3.00",
        "LoanNo": "56656"


    }]
]

I can parse json array with name but in above json there are three arrays without name. How to parse above json in three different arrays?

1

1 Answer 1

1

If you are positive that the data will always come in the stated format, then you can iterate through the result. See below for example:

main(List<String> args) {

  // Define the array of data "object" like this

  List<List<Map<String, dynamic>>> arrayOfData = [
    [
      {"ID": 1, "Date": "11-09-2015", "Balance": 1496693.00},
      {"ID": 2, "Date": "01-10-2015", "Balance": 1496693.00}
    ],
    [
      {"ID": 1, "Date": "03-09-2000", "IntAmount": "003.00"}
    ],
    [
      {"EmployeeId": "000", "DesignationName": "deg"}
    ],
    [
      {"LoanAmount": "00000.00", "IntRate": "3.00", "LoanNo": "56656"}
    ]
  ];

  /* 
    Iterate through the array of "objects" using forEach,
    then, iterate through each resulting array using forEach
  */

  arrayOfData.forEach((datasetArray) => datasetArray.forEach((dataset) => print(dataset)));

  /* 
    ============== RESULT ========

    {ID: 1, Date: 11-09-2015, Balance: 1496693.0}
    {ID: 2, Date: 01-10-2015, Balance: 1496693.0}
    {ID: 1, Date: 03-09-2000, IntAmount: 003.00}
    {EmployeeId: 000, DesignationName: deg}
    {LoanAmount: 00000.00, IntRate: 3.00, LoanNo: 56656} 

  */

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.