json - 将餐厅菜单数据转换为 json
问题描述
我拥有的数据格式-
Beverages
Coffee -
Cafe Latte
Hot 90
Iced 120
Vegan- 50
Soy Milk ()
Coconut Milk ()
Cafe Mocha
Hot 100
Iced 130
Vegan- 50
Soy Milk ()
Coconut Milk ()
Cafe Cappucinno
Hot 90
Iced 120
Vegan- 50
Soy Milk ()
Coconut Milk ()
Cafe Zenzero 100
Vegan- 50
Soy Milk ()
Coconut Milk ()
Cafe Americano 50
Cafe Espresso 50
如何将此餐厅菜单数据转换为 json
我能赚这么多,但不知道如何分类:
{
"Beverages":{
"Coffee":{
"Cafe Latte":{
"Hot":{
"price":90
},
"Iced":{
"price":110
}
}
}
}
}
有一个更好的方法吗?我做错了吗,我对此很陌生
解决方案
我的建议可以帮助您入门:
饮料应该是一系列饮料对象。每个饮料都是一个对象,并具有各种属性,例如name、price、options等。如果有多个选项,则属性的值也应该是一个对象数组。
我建议您查看有关对象的课程,以进一步巩固您的理解。
const beverages = [
{
name: 'Cafe Latte',
category: 'coffee',
options: [
{
name: 'Hot',
price: 90,
},
{
name: 'Iced',
price: 120,
},
],
additionalOptions: [
{
name: 'Vegan',
price: 50,
options: [
{
name: 'Soy Milk',
},
{
name: 'Coconut Milk',
},
],
}
],
},
];
推荐阅读
- html - 由于 Socket.io,我的脚本不起作用
- html - 如何防止css继承?
- r - 如何获得仅由具有 1:1 线和良好轴标签的散点图组成的散点矩阵?
- android - 为一个应用程序自动备份一个数据库文件
- iphone - 有什么方法可以在 iOS 设备中以 react-native 获取可用的 Wifi 列表?
- javascript - 显示:无和 DOM
- django - 使用来自另一个的几个特定字段
- plotly-dash - 如何在不破坏 dcc.RangeSlider 的情况下删除时间戳?
- node.js - 为 IBM Block chain Hyperledger Fabric 运行enrollAdmin.js 时遇到错误
- networking - 无法将 2 个 Centos 虚拟机相互连接