I want to print json response in html page in ionic.please help me

This is my function

ionViewDidLoad() {
var headers = new Headers();
headers.append(‘Content-Type’, ‘application/x-www-form-urlencoded’);
let options = new RequestOptions({ headers: headers });

  .subscribe(data => {
    this.data = data
    //let clients = JSON.parse(this.data)
  }, error => {
    //console.log(error);// Error getting the data
    alert("No Internet connection!")

below my html code


this is json response sending from the serveer:-{“GetAllUsers”: [{“user_id”:“1”,“username”:“Faisal Arif",“useremail”:"faisal@flycoders.com”,“userphone”

if you can’t even format your post correctly don’t expect anyone to answer this question

@FnnHuman what i am wrong?.

@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”

and this is my app ned code below

 .subscribe((res: Response) => {
            this.mydata = res.json();
1 Like


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){
      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

@Sachiyo actually i want to display all data into my html page,like username and email.

@Sachiyo {{post.email}} means.

*ngFor=" let post of mydata">

I see.

Well as you said, you json object is

{“GetAllUsers”: [{“user_id”:“1”,“username”:“Faisal Arif",“useremail”:"faisal@flycoders.com”,“userphone”

Your code should be

*ngFor="let post of mydata.GetAllUsers"

This way, post is your user

{“user_id”:“1”,“username”:“Faisal Arif",“useremail”:"faisal@flycoders.com”,“userphone”

and you can use post.useremail
If you want to display the whole json object at once, you should use JSON.stringify(post)

when i use your code showing an error.

Ok.please give a example of code .if possible

actually am new in ionic. that why.am telling for a demo code

Below code is right?

  .subscribe(data => {
   this.mydata = data;

  }, error => {
    alert("No Internet connection!")

Here’s your code

    let dataTemp = res.json(); //dataTemp is the json object you showed me
    this.data = dataTemp.GetAllUsers; //contains a [] object with all yours users

and in your html

*ngFor="let post of data">

@Sachiyo Thank you so much.its working fine.

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!