gpt4 book ai didi

javascript - 如何访问嵌套的 json 数组以获取每个对象中所有参数的所有值的列表

转载 作者:搜寻专家 更新时间:2023-10-30 21:33:31 25 4
gpt4 key购买 nike

<分区>

我有一个 json 类型

{
"success": true,
"dataPoints": [{
"count_id": 4,
"avg_temperature": 2817,
"startTime": "00:00:00",
"endTime": "00:19:59.999"
}, {
"count_id": 4,
"avg_temperature": 2814,
"startTime": "00:59:59.997",
"endTime": "01:19:59.996"
}, {
"count_id": 4,
"avg_temperature": 2816,
"startTime": "00:39:59.998",
"endTime": "00:59:59.997"
}, {
"count_id": 4,
"avg_temperature": 2825,
"startTime": "02:19:59.993",
"endTime": "02:39:59.992"
}, {
"count_id": 4,
"avg_temperature": 2828,
"startTime": "02:39:59.992",
"endTime": "02:59:59.991"
}, {
"count_id": 4,
"avg_temperature": 2832,
"startTime": "02:59:59.991",
"endTime": "03:19:59.99"
}, {
"count_id": 4,
"avg_temperature": 2841,
"startTime": "03:39:59.989",
"endTime": "03:59:59.988"
}, {
"count_id": 4,
"avg_temperature": 2816,
"startTime": "01:39:59.995",
"endTime": "01:59:59.994"
}, {
"count_id": 5,
"avg_temperature": 2668,
"startTime": "04:19:59.987",
"endTime": "04:39:59.986"
}, {
"count_id": 3,
"avg_temperature": 2711,
"startTime": "05:19:59.984",
"endTime": "05:39:59.983"
}, {
"count_id": 9,
"avg_temperature": 2697,
"startTime": "03:59:59.988",
"endTime": "04:19:59.987"
}, {
"count_id": 4,
"avg_temperature": 2560,
"startTime": "05:59:59.982",
"endTime": "06:19:59.981"
}, {
"count_id": 4,
"avg_temperature": 2837,
"startTime": "03:19:59.99",
"endTime": "03:39:59.989"
}]

我想要这个 json 对象的所有 avg_temperature 值的列表。

getHistoryData() {
this.historyDataService.getHistoryData(this.payload)
.subscribe((data : any) => this.response = data.dataPoints[0].avg_temperature)
}

我正在以这种方式捕获我的响应,它给了我一个特定的值,但我想要 avg_temperature 的所有值。我如何遍历响应/获取所有 avg_temperature 值。类似地,我想将所有其他参数(如 startTime 、 endTime )存储在一个数组中,并在其他地方使用它们

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com