gpt4 book ai didi

javascript - 按照端点请求的预期格式化数据集

转载 作者:行者123 更新时间:2023-12-02 21:00:02 25 4
gpt4 key购买 nike

我正在尝试格式化发送到端点的数据。目前,端点需要某种格式,但我发送的数据与该格式不完全匹配。我发送的数据有额外的括号。请查看下面我的代码与预期的代码。

我要发送的内容

[
[
{
"corporateId": "97765c76-19c3-48b5-8183-d450e72e8f23",
"selectedMAP": [
{
"mapId": 53,
"mapName": "Discovery",
"active": true,
"options": [
{
"optionId": 81,
"optionName": "Keycare",
"memberAmount": 1000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
}
]
},
{
"mapId": 54,
"mapName": "Bestmed",
"active": true,
"options": [
{
"optionId": 83,
"optionName": "Beat 1",
"memberAmount": 1000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
},
{
"optionId": 84,
"optionName": "Beat 2",
"memberAmount": 2000,
"adultDependantAmount": 1000,
"childDependantAmount": 1000,
"active": true
}
]
}
]
}
],
{
"gapCoverProviders": [
{
"id": 0,
"name": "a",
"isActive": true,
"gapCoverOptions": [
{
"id": 0,
"name": "b",
"optionPrice": 111,
"isActive": true
}
]
}
]
}
]

预期结果

{
"corporateId": "string",
"active": true,
"selectedMAP": [
{
"mapId": 0,
"mapName": "string",
"active": true,
"options": [
{
"optionId": 0,
"optionName": "string",
"memberAmount": 0,
"adultDependantAmount": 0,
"childDependantAmount": 0,
"active": true
}
]
}
],
"gapCoverProviders": [
{
"id": 0,
"name": "string",
"isActive": true,
"gapCoverOptions": [
{
"id": 0,
"name": "string",
"isActive": true,
"optionPrice": 0
}
]
}
]
}

我构建的结构如下所示。我有 2 个模型,然后将它们组合成 1 个数据集。

型号 1

export class CompanyMedicalAidProvider {
corporateId: string;
active: boolean = true;
selectedMAP: Array<SelectedMap>;
}

型号 2

export class CompanyGapCoverProvider {
gapCoverProviders: Array<GapCoverProviders>;
}

发布的数据

data = [this.companyMedicalAidProvider, this.companyGapCoverProvider];

我有什么想法可以改变结构吗?我被困在这部分了。

最佳答案

您可以像这样以所需的格式创建新数据

var data = [
[
{
"corporateId": "97765c76-19c3-48b5-8183-d450e72e8f23",
"selectedMAP": [
{
"mapId": 53,
"mapName": "Discovery",
"active": true,
"options": [
{
"optionId": 81,
"optionName": "Keycare",
"memberAmount": 1000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
}
]
},
{
"mapId": 54,
"mapName": "Bestmed",
"active": true,
"options": [
{
"optionId": 83,
"optionName": "Beat 1",
"memberAmount": 1000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
},
{
"optionId": 84,
"optionName": "Beat 2",
"memberAmount": 2000,
"adultDependantAmount": 1000,
"childDependantAmount": 1000,
"active": true
}
]
}
]
}
],
{
"gapCoverProviders": [
{
"id": 0,
"name": "a",
"isActive": true,
"gapCoverOptions": [
{
"id": 0,
"name": "b",
"optionPrice": 111,
"isActive": true
}
]
}
]
}
]

var newData = data[0][0]
newData['gapCoverProviders'] = data[1]['gapCoverProviders'];
console.log(newData)

关于javascript - 按照端点请求的预期格式化数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61379539/

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