2017-03-05 81 views
-1

我需要幫助解決我的錯誤。 我用angular2工作,我得到錯誤。EXCEPTION:位置10的JSON中意外的令牌n

import { Injectable } from '@angular/core'; 
import {Http} from '@angular/http'; 

import 'rxjs/add/operator/map'; 

@Injectable() 

export class PeopleService { 

    constructor(private _http: Http) { } 
    fetchPeople(){ 
    return this._http.get('/assets/people.json') 
       .map(res => res.json()); 
} 

enter image description here};

+0

您可以發佈您JSON和你確認它是有效的? –

+0

你可以使用http://jsonlint.com/來測試你的JSON –

+0

而你的問題是... –

回答

1

很簡單 - 檢查返回的JSON,第10個字符。那裏有什麼不對。這個錯誤意味着JSON不能被解析,因爲結構無效。確保JSON格式良好:

Unexpected token n so - JSON在位置10中有一個n字符,它打破了它的格式。檢查您是否用{}[]關閉了所有數據。

+0

謝謝,這是我的JSON格式 –

+0

感謝Koby Douek –

0

JSON文件無效。字符串應該使用雙引號。

例如 [{ 「名」: 「Smael檢查」, 「狀態」: 「網絡developper」 }]