ionViewDidLoad() {
var headers = new Headers();
headers.append(‘Content-Type’, ‘application/x-www-form-urlencoded’);
let options = new RequestOptions({ headers: headers });
this.http.get("http://www.spangu.com/ionic2/ionicdemo/index.php/GetAllUser")
.subscribe(data => {
this.data = data
//let clients = JSON.parse(this.data)
//alert(clients);
}, error => {
//console.log(error);// Error getting the data
alert("No Internet connection!")
});
};
below my html code
{{post.email}}
this is json response sending from the serveer:-{“GetAllUsers”: [{“user_id”:“1”,“username”:“Faisal Arif",“useremail”:"faisal@flycoders.com”,“userphone”
:“900124578”,“userpass”:“faisal”,“image”:""}]}
@FnnHuman Actually i want to print a specific json object. like username.below is my json object sending from the server.
{“GetAllUsers”: [{“user_id”:“1”,“username”:“Faisal Arif",“useremail”:"faisal@flycoders.com”,“userphone”
:"",“userpass”:"",“image”:""}]}
It is very unclear what exactly you’re trying to display in your html, whats is {{post.email}} supposed to be?
I’m going to assume that you want to display the email of one particular user :
(res : Response) => {
let data = res.json();
for(let user of data.GetAllUsers){
if(user.user_id==whateverUserIdYouWant){
this.data = user.useremail;
}
}
}
Your html code to display the email would be {{data}}
Does that answer your question?
If not, please be more specific
subscribe((res:Response)=>{
let dataTemp = res.json(); //dataTemp is the json object you showed me
this.data = dataTemp.GetAllUsers; //contains a [] object with all yours users
})
Instead of criticizing other people’s format, try to help them by either answering their question or trying to fix the way they post. If you don’t want to apply any of the above options, don’t reply at all. This is the ionicforum where a pro and a newbie can work together. Thanks!