How to get specific return data from a JSON with Ionic 3

0

I think it's simple, but going from Ionic 1 to 3, changed so many things.

I need to get all the returns from my Json from this routine (I actually need the user ID and register 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 Json looks 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"}]
    
asked by anonymous 20.07.2018 / 16:20

1 answer

1

I made a modification so that you see how to turn the return into a JSON object and iterate every item in 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!");
  });
}
    
20.07.2018 / 16:36