gpt4 book ai didi

javascript - Node.js解析时如何获取数据

转载 作者:行者123 更新时间:2023-11-30 14:17:01 24 4
gpt4 key购买 nike

解析时我得到这个答案:

{ 
data: {
type: 'match',
id: 'ae825686-8a74-4363-a1d1-402d5a4207d5',
attributes: {
createdAt: '2018-11-20T17:06:52Z',
titleId: 'bluehole-pubg',
shardId: 'pc-ru',
tags: null,
seasonState: 'progress',
duration: 1823,
stats: null,
gameMode: 'squad-fpp'
},
},
included: [
{
type: 'participant',
id: '0b1b8f78-bb3e-4c0a-9955-9fdf8e33e5b4',
attributes: [Object]
},
{
type: 'participant',
id: '85e74b88-125b-4529-8c3f-fd76bd43b9aa',
attributes: [Object]
},
{
type: 'roster',
id: '6db70dce-b056-4bed-8cc4-6521b83bea50',
attributes: [Object],
relationships: [Object]
},
{
type: 'roster',
id: 'a35db9ae-e559-4474-b922-784e3221f484',
attributes: [Object],
relationships: [Object]
}
]
}

我需要获取具有inculded type:'roster' 和对象内容属性、关系 的数据。我该怎么做?我尝试提取数据数组 console.log(included [0]); 我从 type:'participant' 获取数据。 如此尝试 console.log(包括[{type: 'roster', relationship}]); 作为响应,我收到消息 undefined Please tell me how to get the necessary data.

最佳答案

使用 Array.prototype.filter()

const response = { 
data: {
type: 'match',
id: 'ae825686-8a74-4363-a1d1-402d5a4207d5',
attributes: {
createdAt: '2018-11-20T17:06:52Z',
titleId: 'bluehole-pubg',
shardId: 'pc-ru',
tags: null,
seasonState: 'progress',
duration: 1823,
stats: null,
gameMode: 'squad-fpp'
},
},
included: [
{
type: 'participant',
id: '0b1b8f78-bb3e-4c0a-9955-9fdf8e33e5b4',
attributes: [Object]
},
{
type: 'participant',
id: '85e74b88-125b-4529-8c3f-fd76bd43b9aa',
attributes: [Object]
},
{
type: 'roster',
id: '6db70dce-b056-4bed-8cc4-6521b83bea50',
attributes: [Object],
relationships: [Object]
},
{
type: 'roster',
id: 'a35db9ae-e559-4474-b922-784e3221f484',
attributes: [Object],
relationships: [Object]
}
]
}

const arrayWithRoster = response.included.filter(item => item.type === 'roster');

console.log(arrayWithRoster);

关于javascript - Node.js解析时如何获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53429113/

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