解析 Angular 6 模板中的 Json 数据
Parse Json data in Angular 6 Template
我收到 JSON 如下回复,
{
"Meta Data" : {
"ticker" : "NEE",
"datapoints" : 320,
"credit cost" : 320,
"Time Zone" : "America/New_York",
"last refreshed" : "06/17/2019 at 09:27AM ET"
},
"Realtime Stock price" : [ {
"ticker" : "NEE",
"date" : "20190614",
"minute" : "15:58:01",
"volume" : 1028861,
"price" : 207.02,
"timezone" : "EDT",
"timezone_name" : "America/New_York",
"gmt_offset" : -14400
}, {
"ticker" : "NEE",
"date" : "20190614",
"minute" : "15:57:00",
"volume" : 996057,
"price" : 207.14,
"timezone" : "EDT",
"timezone_name" : "America/New_York",
"gmt_offset" : -14400
}]}
这是我的代码,
allPrice: Array<object> = [];
getShareData(){
this.dataservice.getSharePrice().subscribe(data=>{
this.allPrice=data['Realtime Stock pric'];
console.log("Show Price"+JSON.stringify(this.allPrice[1]));
})
}
但我没有在我的模板中获取价格值。我也尝试使用地图
this.allPrice=data['Realtime Stock pric'].map(d=>d.price);
但这也不起作用。
我能做什么?请推荐
应该是
this.allPrice=data['Realtime Stock price'];
不是
this.allPrice=data['Realtime Stock pric'];
我收到 JSON 如下回复,
{
"Meta Data" : {
"ticker" : "NEE",
"datapoints" : 320,
"credit cost" : 320,
"Time Zone" : "America/New_York",
"last refreshed" : "06/17/2019 at 09:27AM ET"
},
"Realtime Stock price" : [ {
"ticker" : "NEE",
"date" : "20190614",
"minute" : "15:58:01",
"volume" : 1028861,
"price" : 207.02,
"timezone" : "EDT",
"timezone_name" : "America/New_York",
"gmt_offset" : -14400
}, {
"ticker" : "NEE",
"date" : "20190614",
"minute" : "15:57:00",
"volume" : 996057,
"price" : 207.14,
"timezone" : "EDT",
"timezone_name" : "America/New_York",
"gmt_offset" : -14400
}]}
这是我的代码,
allPrice: Array<object> = [];
getShareData(){
this.dataservice.getSharePrice().subscribe(data=>{
this.allPrice=data['Realtime Stock pric'];
console.log("Show Price"+JSON.stringify(this.allPrice[1]));
})
}
但我没有在我的模板中获取价格值。我也尝试使用地图
this.allPrice=data['Realtime Stock pric'].map(d=>d.price);
但这也不起作用。
我能做什么?请推荐
应该是
this.allPrice=data['Realtime Stock price'];
不是
this.allPrice=data['Realtime Stock pric'];