I'm struggling to convert a JSON response from a Laravel API into an array in my Ionic 3 app.
Below is the JSON structure:
https://i.sstatic.net/izRAV.png
Object {
id_oiseau: 1,
nom_commun: "Hirondelle",
lieu_signalement: "Foret",
date_signalement: "2017-05-16",
condition_signalement: "Aile coincee sous branche",
date_reception:"2017-05-16",
date_renvoi:"2017-05-02",
and more...
}
I have created a provider to fetch this JSON data for my Ionic app:
export class BirdService {
returnedData;
headers: any;
options: any;
constructor(public http: Http) {
this.headers = new Headers();
this.headers.append('Content-Type', 'application/json');
}
getRemoteData(): Observable<any> {
return this.http.get('http://extranet.local/api/v1/bird/1', this.headers).map(res => res.json());
}
}
And here is the function I'm using to convert the JSON:
export class HistoryPage {
constructor(public navCtrl: NavController, public serviceOne: BirdService) {}
ionViewDidLoad() {
this.serviceOne.getRemoteData().subscribe(
data => {
let list: History[] = data;
console.log(data);
});
}
}
However, I am facing issues as the JSON file remains in its original JSON format. I tried using parseJSON with jQuery but encountered an error stating "Cannot read property 'parseJSON' of undefined". I also attempted to use Angular's fromJson method, but Ionic couldn't recognize the name "angular". Any suggestions on how to resolve this issue would be greatly appreciated!