I’m getting data in ionic 2 through call service and getting o/p but It is returns data with slash
My code is here and I have to display data in drop down also
this.http.get('http://discountapp.studyfield.com/VendorService.asmx/ViewDiscountTypeData?type=discounttype')
.subscribe(data => {
//this.cat = JSON.stringify(data);
alert(JSON.stringify(data));
},
err => {
alert("Error : " + err);
});
vnyksj
August 10, 2017, 3:36pm
2
Did you tried to map your response into json format before Subscribing?
It doesn’t make sense to call JSON.stringify()
on a Response
object in the first place, but when you stringify a string, things get escaped.
I used map before this but it showing an error ’ property map does not exist on observable '…So I tried with this .I used map using following code
import { Http, Response, Headers, RequestOptions} from ‘@angular /http’;
import ‘rxjs/add/operator/map’;
this.http.get('http://discountapp.studyfield.com/VendorService.asmx/ViewDiscountTypeData?type=discounttype') .map(data => {
//this.cat = JSON.stringify(data);
alert(JSON.parse(JSON.stringify(data)));
alert("Latest");
},
err => {
alert("Error : " + err);
});
but It throws error
I’m working with ionic 2 is first time for me…So I’m trying to call Web API
So I want to see data which comes from server and for that I alert it using JSON.strignify()
If this is wrong way then please suggest me how can I do that
vnyksj
August 11, 2017, 5:56am
6
You have to map the response into json() format before subscribing the data. Check out the below code.
this.http.get('http://discountapp.studyfield.com/VendorService.asmx/ViewDiscountTypeData?type=discounttype')
.map((response: Response) => response.json())
.subscribe(data => {
//this.cat = JSON.stringify(data);
alert(JSON.stringify(data));
},
err => {
alert("Error : " + err);
});
}
Let me know how it will go…
this.http.get('http://discountapp.studyfield.com/VendorService.asmx/ViewDiscountTypeData?type=discounttype')
.subscribe(data => {
//this.cat = JSON.stringify(data);
this.discountTypes = data.json().Data;
console.log("Success");
},
err => {
alert("Error : " + err);
});