I am using ionic2, and I'am using http post request to get data from webservice and the returned data is:
Response {_body: "{"Status":{"list all categories":[{"id":9,"name_en…18}],"message":["All categories."],"version":27}}", status: 200, ok: true, statusText: "OK", headers: Headers…} headers : Headers ok : true status : 200 statusText : "OK" type : 2 url : "http://safe-pay.co/safepay/public/api/user" _body : "{"Status":{"list all categories":[{"id":9,"name_en":"Telecom","name_ar":"\u0627\u062a\u0635\u0627\u0644\u0627\u062a","image":"http://safe-pay.co/safepay/public/uploadedimg/categories/5937ec7b75164.PNG","description":"Telecom","cat_enet_id":1},{"id":7,"name_en":"Online Vouchers","name_ar":"\u0628\u0637\u0627\u0642\u0627\u062a \u062a\u0633\u0648\u0642 \u0639\u0628\u0631 \u0627\u0644\u0627\u0646\u062a\u0631\u0646\u062a","image":"http://safe-pay.co/safepay/public/uploadedimg/categories/5937f109a226b.png","description":"Online Voucher","cat_enet_id":5},{"id":8,"name_en":"TV Channels","name_ar":"\u0645\u062d\u0637\u0627\u062a \u062a\u0644\u0641\u0632\u064a\u0648\u0646\u064a\u0629","image":"http://safe-pay.co/safepay/public/uploadedimg/categories/5937ecb48cef3.PNG","description":"TV channels","cat_enet_id":6},{"id":10,"name_en":"Digital Games","name_ar":"\u0627\u0644\u0639\u0627\u0628 \u0627\u0646\u062a\u0631\u0646\u062a","image":"http://safe-pay.co/safepay/public/uploadedimg/categories/5937eccc27ce8.png","description":"Games","cat_enet_id":17},{"id":11,"name_en":"Entertainment","name_ar":"\u0627\u0644\u062a\u0631\u0641\u064a\u0647 \u0644\u0644\u0623\u0637\u0641\u0627\u0644","image":"http://safe-pay.co/safepay/public/uploadedimg/categories/5937f5ae97fe6.png","description":"Games","cat_enet_id":18}],"message":["All categories."],"version":27}}" proto : Body
this is the function:
getCategories() {
let objData = {"Data":{
"action": "CATEGORIES",
"lang": "AR"
},
"Request": {
}
}
var headers = new Headers();
headers.append('Content-Type', 'application/json');
this.http.post(this.userUrl, objData, {headers:headers})
.subscribe(data => {
this.categories = data
console.log("categories array ",this.categories," data ",Promise.resolve(data));
}, error => {
console.log("Oooops! ",error);
});
}
how can I get the data from the array
You should be mapping it to json()
format
this.http.post(this.userUrl, objData, {headers:headers})
.map(response=><T>response.json())
...
Note: importing map operator is required which can be done from
import 'rxjs/add/operator/map';
and T
type to which you want to convert the json().