javascript - SyntaxError unexpected token u in JSON on position 0 Angular2 -


i tried make server dummy data.

here system.js config (since have different routing, seemed work fine till now)

system.config({              // baseurl node_modules             baseurl: '/plugins/dashboard/assets/@@version@@/node_modules',             defaultjsextensions: true         });         system.import('/plugins/dashboard/assets/@@version@@/app/main')                 .then(null, console.error.bind(console)); 

here service:

import {injectable}     'angular2/core'; import {http, response} 'angular2/http'; //import {observable }     'rxjs/observable'; import {observable} 'rxjs/rx';  import {newsletter} "../objects/newsletter";   @injectable()  export class newsletterservice { constructor (private http: http) {}  //need change url private _mynewsletterurl = "http://epub-core.dev.prisma-it.com:8888/plugins/dashboard/assets/@@version@@/app/data/newsletter.json";  // url web api  getnewsletter () {     console.log(this._mynewsletterurl);     console.log(this.http.get(this._mynewsletterurl));     return this.http.get(this._mynewsletterurl)         .map(res => <newsletter[]> res.json().data)         // eyeball objects json objects in console | mapping purposes         .do(data => console.log(json.parse(json.stringify(data))))             .catch(this.handleerror);    }    private handleerror (error: response) {     // in real world app, may send error remote logging infrastructure     // instead of logging console     console.error(error);     return observable.throw(error.json().error || 'server error');   } } 

however, if change console log console.log(data) returning undefined.

i looked everywhere, none of answers solved case. might problem system js, since else seems work fine, cannot find how fix this.

this response in console:

console response:

enter image description here

json.stringify(undefined) results in invalid json, why json.parse(json.stringify(data)) throws.

you might change code to

json.parse(json.stringify(data || null )) 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -