[英]How to get values from json nested objects
{
"Petition to file": [
{
"description": "fileing description",
"period": "30 days",
"fees": "500"
}
],
"Appearing before inspection": [
{
"description": "Appearence Description",
"period": "10 days",
"fees": "1500"
}
],
"Passing orders for a recording of statements": [
{
"description": "passing order description",
"period": "50 days",
"fees": "1000"
}
],
"Hearing of petition": [
{
"description": "Hearing of petition description",
"period": "55 days",
"fees": "2000"
}
],
"Decree of petition": [
{
"description": "decreeof description",
"period": "70 days",
"fees": "5000"
}
]
}
How to get the values of nested child headings.如何获取嵌套子标题的值。 It is dynamic content.Also i need to fetch the values of nested objects that is period,fess,description.
它是动态内容。我还需要获取嵌套对象的值,即周期、费斯、描述。 I'm using typescript program that is in angular cli
我正在使用 angular cli 中的 typescript 程序
here is complete working example StackBlitz Link , Your main logic of traversing dynamic object entries is...这是完整的工作示例StackBlitz Link ,您遍历动态 object 条目的主要逻辑是......
ngOnInit(){
Object.keys(this.datafromDatabase).forEach(data =>{
this.datafromDatabase[data].map(key =>{
this.data.push(key)
});
})
}
Your Template file is...您的模板文件是...
<div *ngFor="let key of data">
{{key.description}}
</div>
<div>
{{data |json}}
</div>
var something = consts['Petition to file'];
usually thats the way to get the values inside keys通常这就是获取键内值的方法
so now the new variable something
=所以现在新变量
something
=
[
{
"description": "fileing description",
"period": "30 days",
"fees": "500"
}
]
now if u want description
现在如果你想要
description
var descriptionVariable = consts['description'];
so descriptionVariabe's value is fileing description
所以 descriptionVariabe 的值是
fileing description
let list = { "Petition to file": [ { "description": "fileing description", "period": "30 days", "fees": "500" } ], "Appearing before inspection": [ { "description": "Appearence Description", "period": "10 days", "fees": "1500" } ], "Passing orders for a recording of statements": [ { "description": "passing order description", "period": "50 days", "fees": "1000" } ], "Hearing of petition": [ { "description": "Hearing of petition description", "period": "55 days", "fees": "2000" } ], "Decree of petition": [ { "description": "decreeof description", "period": "70 days", "fees": "5000" } ] } for (let [key, value] of Object.entries(list)) { console.log(key); console.log(value); }
Use Object.entries
使用
Object.entries
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.