如何在angular2中创建json对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40150898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:39:59 来源:igfitidea点击:
how to create json object in angular2
提问by Ola Zeyad
i want to create J SON object in angular2 like this:
我想像这样在 angular2 中创建 J SON 对象:
{ "classifications": [
{ "type1" : [{"name":"text"},{"name":"text2"},{"name":"text2"}]} ,
{ "type2" : [{"name":"image"},{"name":"img2"},{"name":"img3"},{"name":"img4"}]} ,
{ "type3" : [{"name":"mp3"}]}
]
}
is this the right way or not?? if not then how to make it and how to get data from this J SON object??
这是正确的方法吗?如果没有,那么如何制作它以及如何从这个 J SON 对象中获取数据?
回答by Günter Z?chbauer
let x = { "classifications": [
{ "type1" : [{"name":"text"},{"name":"text2"},{"name":"text2"}]} ,
{ "type2" : [{"name":"image"},{"name":"img2"},{"name":"img3"},{"name":"img4"}]} ,
{ "type3" : [{"name":"mp3"}]}
]
}
console.log(x.classifications[0].type1[0].name);

