-1

我有从 ORDS 服务器检索的 json 格式数据,它看起来像这样:

{"items":[{"cust_code":"C00013","cust_name":"Holmes","cust_city":"London","working_area":"London","cust_country":"UK","grade" :2,"opening_amt":6000,"receive_amt":5000,"payment_amt":7000,"outstanding_amt":4000,"phone_no":"BBBBBB","agent_code":"A003"},{"cust_code":" C00001","cust_name":"Micheal","cust_city":"New York
","working_area":"New York","cust_country":"USA","grade":2,"opening_amt":3000," receive_amt":5000,"payment_amt":2000,"outstanding_amt":6000,"phone_no":"CCCCCC","agent_code":"A008"},{"cust_code":"C00020","cust_name":"Albert","cust_city":"纽约
","working_area":"New York","cust_country":"USA","grade":3,"opening_amt":5000,"receive_amt":7000,"payment_amt":6000,"outstanding_amt":6000," phone_no":"BBBBSBB","agent_code":"A008"},{"cust_code":"C00025","cust_name":"Ravindran","cust_city":"Bangalore","working_area":"Bangalore"," cust_country":"印度","grade":2,"opening_amt":5000,"receive_amt":7000,"payment_amt":4000,"outstanding_amt":8000,"phone_no":"AVAVA","agent_code":" A011 "},{"cust_code":"C00015","cust_name":"Stuart","cust_city":"伦敦
","working_area":"London","cust_country":"UK","grade":1,"opening_amt":6000,"receive_amt":8000,"payment_amt":3000,"outstanding_amt":11000,"phone_no ":"GFSGERS","agent_code":"A003 "}],"hasMore":false,"limit":25,"offset":0,"count":5,"links":[{"rel": "self","href":"http://localhost:9000/ords/demo/customers/getAll/"},{"rel":" describeby","href":"http://localhost:9000/ ords/demo/metadata-catalog/customers/getAll/"},{"rel":"first","href":"http://localhost:9000/ords/demo/customers/getAll/"}]}

所以我想知道是否有一种方法可以分解物品部分并使用钓鱼器将其放入表格中。

我尝试在我的 ts 文件中使用这种方式:

http.get('http://localhost:9000/ords/demo/customers/getAll/')
    .subscribe(data => this.items = data);

但我不断收到此错误:

错误:尝试比较“[object Object]”时出错。只允许使用数组和可迭代对象

4

1 回答 1

0

你想要的数组在items属性中,所以你必须这样做

http.get('http://localhost:9000/ords/demo/customers/getAll/')
    .subscribe(data => this.items = data.items);
于 2020-09-16T19:33:21.190 回答