Can't figure out how to parse Json URL


#1

Hi, I am new to the framework and have been trying with failed attempts to parse some Json from a URL. I just want to be able to see if the parse is working with a json object in a console.log output. If anyone can point me in the right direction for how to accomplish this it would be greatly appreciated. Thanks!
Json url: http://app.toronto.ca/cc_sr_v1_app/data/edc_eventcal_APR?limit=500

home.ts

export class HomePage {

eventData: any;
loading: any;

//injecting HttpProvider with angular 2 dependancy in ctor + Loader
constructor(public navCtrl: NavController, private httpProvider:HttpProvider, public loadingCtrl: LoadingController) {

this.loading = this.loadingCtrl.create({
  content: `
  <ion-spinner ></ion-spinner>`
});

this.getdata();
 }

getdata(){

this.httpProvider.getJsonData().subscribe(
 result => {
this.eventData=result.calEvent.children;
console.log("it works...: " + this.eventData);
},
err =>{
console.error("Error : " +err);
},
() => {
console.log('getData completed');
}
);

}
}

providers https.ts

getJsonData(){
return this.http.get('http://app.toronto.ca/cc_sr_v1_app/data/edc_eventcal_APR?limit=500').map(res => res.json());
}
}

home.html

<ion-content padding>

 <ion-list >
<ion-item text-wrap *ngFor="let item of eventData" >
<p >{{item.calEvent.orgType}}</p>
</ion-item>
</ion-list>

</ion-content>

#2

@abpatola Here is your solution

this.httpProvider.getJsonData().subscribe(
        data => {
console.log(data);
this.eventData=JSON.parse(JSON.stringify(data));
console.log(this.eventData);

},
err =>{
console.error("Error : " +err);
},
() => {
console.log('getData completed');
}
);

#3

would you be able to explain why this is the solution? thanks.


#4

First read your question and think what you ask for.
then add this code in your http function and you can see data into console.
thats it!!!