How to parse json lists in flutter

2020-06-30 05:25发布

问题:

How can we parse such type of List data in Flutter? I tried different models but failed. Following is the data:

[
    {
        "course":"Computer Architecture Fall 2018 - KHI",
        "pending_assignment":[
            {
                "name":"OOAD Project Fall 2018 Section B & D",
                "dueDate":"Dec 14, 2018 10:00 pm"
            }
        ]
    },
    {
        "course":"Object Oriented Analysis and Design Fall 2018 - KHI",
        "pending_assignment":[
            {
                "name":"OOAD Project Fall 2018 Section B & D",
                "dueDate":"Dec 14, 2018 10:00 pm"
            }
        ]
    }
]

回答1:

As you can check with this website (http://json.parser.online.fr/), that JSON is not valid and contains errors.

For how to parse JSON in general, you can use the json.decode(jsonString); function from the dart:convert package. For more information on that you can check out this site: https://flutter.io/docs/development/data-and-backend/json