从多个表创建多维 JSon 数组
我正在尝试创建一个具有如下结构的 json 数组:
var cars = [
{name: 'Honda', models: [
{name: 'Accord', features: ['2dr', '4dr']},
{name: 'CRV', features: ['2dr', 'Hatchback']},
{name: 'Pilot', features: ['base', 'superDuper']}
]},
{name: 'Toyota', models: [
{name: 'Prius', features: ['green', 'superGreen']},
{name: 'Camry', features: ['sporty', 'square']},
{name: 'Corolla', features: ['cheap', 'superFly']}
]}
];
来自我的 MySQL 数据库中的 3 个表(carmakes
、carmake_models
和 carmake_options
)。 最好的方法是什么?
这些表的结构如下:
汽车制造商: ID、汽车名称
carmake_models:模型父级,模型名称
carmake_options: OptionParent,OptionName
I am trying to create a json array with a structure like this:
var cars = [
{name: 'Honda', models: [
{name: 'Accord', features: ['2dr', '4dr']},
{name: 'CRV', features: ['2dr', 'Hatchback']},
{name: 'Pilot', features: ['base', 'superDuper']}
]},
{name: 'Toyota', models: [
{name: 'Prius', features: ['green', 'superGreen']},
{name: 'Camry', features: ['sporty', 'square']},
{name: 'Corolla', features: ['cheap', 'superFly']}
]}
];
From 3 tables (carmakes
, carmake_models
and carmake_options
) in my MySQL database.
What is the best way to go about it?
The tables are structured as follows:
carmakes: ID, CarName
carmake_models: ModelParent, ModelName
carmake_options: OptionParent, OptionName
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有足够的信息来回答你的问题。但是,您可能会更好地创建 JSON,如下所示:
I don't have enough information to answer your question. However, you might do better to create JSON more like this: