关于如何从嵌套的json响应中打印数据的问题,我一直被困在一个星期左右,而我几乎白天和黑夜都在尝试这种方法。我已经用Google搜索了所有可能的帮助,但找不到任何帮助。我别无选择,因此我正在寻求帮助!
我的回应
{
"data": {
"1": {
"Sales": {
"Total Sales": "-",
"Non-VAT": "-",
"Baskets": "-",
"Avg Basket": "-",
"Known Customers": "-",
"Discounts": "-",
"Owners": "-",
"Staff": "-",
"Margin": "-",
"Profit": "-"
},
"Accounts": {
"Register": "-",
"Cash Close Date": "-",
"Cash Excess\/ Short": "-",
"Cash In Hand": "-"
},
"Alerts": {
"-ve Batches": "-",
"-ve QOH": "-",
"Items": "-",
"Stock": "-",
"Replication": "-"
}
},
"2": {
"Sales": {
"Total Sales": "-",
"Non-VAT": "-",
"Baskets": "-",
"Avg Basket": "-",
"Known Customers": "-",
"Discounts": "-",
"Owners": "-",
"Staff": "-",
"Margin": "-",
"Profit": "-"
},
"Accounts": {
"Register": "-",
"Cash Close Date": "-",
"Cash Excess\/ Short": "-",
"Cash In Hand": "-"
},
"Alerts": {
"-ve Batches": "-",
"-ve QOH": "-",
"Items": "-",
"Stock": "-",
"Replication": "-"
}
},
"3": {
"Sales": {
"Total Sales": "-",
"Non-VAT": "-",
"Baskets": "-",
"Avg Basket": "-",
"Known Customers": "-",
"Discounts": "-",
"Owners": "-",
"Staff": "-",
"Margin": "-",
"Profit": "-"
},
"Accounts": {
"Register": "-",
"Cash Close Date": "-",
"Cash Excess\/ Short": "-",
"Cash In Hand": "-"
},
"Alerts": {
"-ve Batches": "-",
"-ve QOH": "-",
"Items": "-",
"Stock": "-",
"Replication": "-"
}
},
"4": {
"Sales": {
"Total Sales": "-",
"Non-VAT": "-",
"Baskets": "-",
"Avg Basket": "-",
"Known Customers": "-",
"Discounts": "-",
"Owners": "-",
"Staff": "-",
"Margin": "-",
"Profit": "-"
},
"Accounts": {
"Register": "-",
"Cash Close Date": "-",
"Cash Excess\/ Short": "-",
"Cash In Hand": "-"
},
"Alerts": {
"-ve Batches": "-",
"-ve QOH": "-",
"Items": "-",
"Stock": "-",
"Replication": "-"
}
},
"5": {
"Sales": {
"Total Sales": "-",
"Non-VAT": "-",
"Baskets": "-",
"Avg Basket": "-",
"Known Customers": "-",
"Discounts": "-",
"Owners": "-",
"Staff": "-",
"Margin": "-",
"Profit": "-"
},
"Accounts": {
"Register": "-",
"Cash Close Date": "-",
"Cash Excess\/ Short": "-",
"Cash In Hand": "-"
},
"Alerts": {
"-ve Batches": "-",
"-ve QOH": "-",
"Items": "-",
"Stock": "-",
"Replication": "-"
}
},
"6": {
"Sales": {
"Total Sales": "-",
"Non-VAT": "-",
"Baskets": "-",
"Avg Basket": "-",
"Known Customers": "-",
"Discounts": "-",
"Owners": "-",
"Staff": "-",
"Margin": "-",
"Profit": "-"
},
"Accounts": {
"Register": "-",
"Cash Close Date": "-",
"Cash Excess\/ Short": "-",
"Cash In Hand": "-"
},
"Alerts": {
"-ve Batches": "-",
"-ve QOH": "-",
"Items": "-",
"Stock": "-",
"Replication": "-"
}
},
"7": {
"Sales": {
"Total Sales": "-",
"Non-VAT": "-",
"Baskets": "-",
"Avg Basket": "-",
"Known Customers": "-",
"Discounts": "-",
"Owners": "-",
"Staff": "-",
"Margin": "-",
"Profit": "-"
},
"Accounts": {
"Register": "-",
"Cash Close Date": "-",
"Cash Excess\/ Short": "-",
"Cash In Hand": "-"
},
"Alerts": {
"-ve Batches": "-",
"-ve QOH": "-",
"Items": "-",
"Stock": "-",
"Replication": "-"
}
}
}
}
我的ts文件
export class HomePage {
data:any;
keyss:any;
alldata: Observable<any>; //<-- this add first
keys:Observable<any>;
constructor(public navCtrl: NavController,
private http: Http) {
// window.open("http://google.com",'_system', 'location=yes');
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let options = new RequestOptions({ headers: headers });
this.http.get('http://url/file/file.php',options)
.map(res => res.json())
.subscribe(data => {
console.log("Api Fired",data);
this.data =data;
var info=JSON.parse(JSON.stringify(this.data));
this.alldata = info.data; //<--this add
console.log("Api Fired 1",this.alldata);
this.keys = this.alldata;
});
}
}
我的html文件
<ion-content padding>
<ion-content>
<ion-grid>
<ion-row>
<ion-col *ngFor = "let key of keys?.alldata">
</ion-col>
<ion-col>
</ion-col>
<ion-col>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
请帮助我,这是我的项目工作,我需要帮助。请
答案 0 :(得分:0)
您可以做的是这样的:
for(let i in this.alldata) console.log(this.alldata[i])
如果不起作用,请尝试而不是,我不记得是哪一个