SyntaxError unerwartetes token u in JSON auf position 0 Angular2

Habe ich versucht, einen server mit einigen dummy-Daten.

Hier ist meine System.js Config (da habe ich einen etwas anderen routing, das schien zu funktionieren bis jetzt)

System.config({

            //baseURL to 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));

hier ist mein service:

import {Injectable}     from 'angular2/core';
import {Http, Response} from 'angular2/http';
//import {Observable }     from 'rxjs/Observable';
import {Observable} from 'rxjs/Rx';

import {newsLetter} from "../objects/newsLetter";


@Injectable()

export class newsLetterService {
constructor (private http: Http) {}

//Need to change this URL
private _myNewsLetterUrl = "http://epub-core.dev.prisma-it.com:8888/plugins/dashboard/assets/@@version@@/app/data/newsLetter.json";  //URL to 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 as json objects in the console | mapping purposes
        .do(data => console.log(JSON.parse(JSON.stringify(data))))
            .catch(this.handleError);

  }

  private handleError (error: Response) {
    //in a real world app, we may send the error to some remote logging infrastructure
    //instead of just logging it to the console
    console.error(error);
    return Observable.throw(error.json().error || 'Server error');
  }
}

jedoch, wenn ich die Konsole zu Konsole.log(data) es ist wieder undefined.

Ich überall gesucht, aber keine Antworten lösen mein Fall. Es könnte ein problem mit dem system js, aber da alles andere scheint zu funktionieren, ich kann wirklich nicht finden, wie dieses Problem zu beheben.

Dies ist die Antwort in der Konsole:

Konsole Antwort:

SyntaxError unerwartetes token u in JSON auf position 0 Angular2

prüfen Sie die Reaktion in der browser-Registerkarte "Netzwerk" .. Sie sind immer ein falsch json oder nicht-einen-richtigen-Ergebnis, wie Sie codiert für
Sie hatten Recht. Meine JSON-war nicht gültig. danke für die Antwort aber!

InformationsquelleAutor Astrid Karsten | 2016-05-09

Schreibe einen Kommentar