Ionic , how to get exact data from hard coded local JSON

Hi every one , i tried to create my own json file to use to verify login , then created a provider called " redditdata.ts" to get the data from my json file (professeur.json) , i got in an observable correctly when i open the console , but i want to retrieve the password and the username , wich i will use in my login verification , how can i do that please ?? , thanks , this is my code below … J4
redditdata.ts ( the provider to acess my json file)


professeur.ts

my html button code (professeur.html)
<button (click)=“login()” ion-button color=“danger” block outline>LOGIN

1 Like

Just try to use php to generate web service instead of hard coded

1 Like

i will try that , but for now i need to know how i will get the username and password to use it for verification from the JSON i had create it

Never store passwords on device. It’s a security disaster.

1 Like

Hi Souma,

The others have rightly pointed out that storing credentials in your source files is bad practice. However, with regard to your question… =>

change getRemoteData() to reflect:

import { Observable } from 'rxjs/Observable';

getRemoteData(): Observable<Object> {
 return this.http.get('assets/data/professeur.json');
}

change ionViewDidLoad() to reflect:

ionViewDidLoad() {
 this.redditService.getRemoteData().subscribe(data => {
  console.log(data.results[0].username);
  console.log(data.results[1].password);
  //Any further operations here you want to perform on data when it comes in
 });
}
1 Like

you could try in this way

this.http.get('assets/data/filename.json').map(res => res.json()).subscribe(data => {
               console.log( data);
          })

Note: Store the respective json file in assets/data/filename.json