SyntaxError: Unexpected token < in JSON at position 0 from google alert link


#1

Hello,

I have a problem when making a feed list from google alert link such as below:


this.http.get('https://www.google.com/alerts/feeds/12580094399189786947/2757509485669966056').map(res => res.json()).subscribe((posts) => {
	    console.log(posts);
	    this.list = posts;
    }, (err) => {
	    console.log(err);
    });

Error Message on Console:

SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Response.Body.json (http.es5.js:796)
    at MapSubscriber.project (home.ts:28)
    at MapSubscriber._next (map.js:77)
    at MapSubscriber.Subscriber.next (Subscriber.js:89)
    at XMLHttpRequest.onLoad (http.es5.js:1205)
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (core.es5.js:4116)
    at t.invokeTask (polyfills.js:3)
    at n.runTask (polyfills.js:3)
    at XMLHttpRequest.invoke (polyfills.js:3)

My Ionic App Version:
Cordova CLI: 7.0.0
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.6
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.10.1
Xcode version: Not installed

How I can fix it?


#2

Well, don’t call json() on it. It isn’t JSON.


#3

So What I should do now?


#4

Either find a different source for the data that is actually JSON, or figure out some way to parse what is coming from that URL, which looks like RSS to me.