Flutter中的JSON解码

时间:2018-07-21 19:01:57

标签: dart flutter

我目前正在开发健康应用程序,我不知道如何使用flutter解码此示例json。我想提取“ heartRateZones”列表。

{
    "activities-heart": [{
        "dateTime": "2015-08-04",
        "value": {
            "customHeartRateZones": [],
            "heartRateZones": [{
                "caloriesOut": 740.15264,
                "max": 94,
                "min": 30,
                "minutes": 593,
                "name": "Out of Range"
            }, {
                "caloriesOut": 249.66204,
                "max": 132,
                "min": 94,
                "minutes": 46,
                "name": "Fat Burn"
            }, {
                "caloriesOut": 0,
                "max": 160,
                "min": 132,
                "minutes": 0,
                "name": "Cardio"
            }, {
                "caloriesOut": 0,
                "max": 220,
                "min": 160,
                "minutes": 0,
                "name": "Peak"
            }],
            "restingHeartRate": 68
        }
    }]
}

请帮助...
JSON托管在https://api.myjson.com/bins/g05ga上。

1 个答案:

答案 0 :(得分:-1)

根据to the documentation,您应该使用json.decode,然后才能提取所需的内容。

然后您可以像activities-heart.value.heartRateZones这样使用它