gpt4 book ai didi

javascript - 如何在 JSON 中存储层次结构?

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

如何在 JSON 中存储层次结构?

我有以下层次结构:

层次结构:

 1:Publish, "Long description of Publish service", is_default
7: 7 days, 150
14:14 days, 600, +200%
30:1 month, 1350, +300%
2:Premium, "Long description..."
14:14 days, 150
30:1 month, 600
60:2 month, 1500
3:SuperPremium, "Long description...", disabled
30:1 month, 150
60:2 month, 600
90:3 month, 1500, disabled

哪里:

  • “Publish, Premium, SuperPremium” - 是服务。 1,2,3 - 服务 ID。

  • “7 天、14 天、28 天”- 是服务参数。 7,14,28 - 参数 ID。

  • 参数取决于服务。

下图说明了这一点:

enter image description here

需要 JSON 格式的精简可用结构。

用 JSON 表示这种层次结构的最佳方式是什么?

最佳答案

我会做类似的事情:

[
{
"Service":"Publish",
"Desc":"Long description of Publish serive",
"Params":[
{
"Days":"7",
"Desc":"7 Days",
"Cost":150
},
{
"Days":"14",
"Desc":"14 Days",
"Cost":600,
"Extra":"+200%"
},{...}
]
}, {...}, {...}
]

关于javascript - 如何在 JSON 中存储层次结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11681884/

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