How to Get Specific Return Data from a JSON with Ionic 3

Asked

Viewed 593 times

0

I believe it’s simple, but coming out of Ionic 1 to 3 has changed so many things.

I need to take all my Json returns from this routine (I actually need the user ID and log in localstorage):

submit(){
      var email = this.data.email;
      var senha = this.data.senha;
    var link = 'http://localhost/webapi/consultarEmailSenha.php?email='+email+'&senha='+senha;
       //var myData = JSON.stringify({email: this.data.email}) + JSON.stringify({senha: this.data.senha});

       console.log(link);

       this.http.get(link)
       .subscribe(data => {
           this.data.response = data["_body"]; //https://stackoverflow.com/questions/39574305/property-body-does-not-exist-on-type-response
           console.log(this.data.response[0]);
           console.log(this.data.response[1]);
           console.log(this.data.response[2]);
           console.log(this.data.response[3]);
           console.log(this.data.response[3]);
       }, error => {
           console.log("Oooops!");
       });

The return of the Json is like this:

[{"idusuarios":"1","nome":"Ramos J","email":"[email protected]","celular":null,"telefone":"","data_nascimento":"1978-07-19","altura":null,"peso":null,"gordura":null,"vo2":null,"senha":"teste"}]

1 answer

1


I made a modification so you can see how to turn the return into a JSON object and iterate each item of the array.

submit(){
  var email = this.data.email;
  var senha = this.data.senha;
  var link = 'http://localhost/webapi/consultarEmailSenha.php?email='+email+'&senha='+senha;

  this.http.get(link).subscribe(data => {
       var array = JSON.parse(data);
       json.forEach(element => {
           console.log(element.idusuarios);
       });
  }, error => {
       console.log("Oooops!");
  });
}
  • It worked @Nilsonuehara. I just changed a little: var array = JSON.parse(this.data.Response); array.foreach(element => { console.log(element.idusuarios); });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.