2017-04-15 15 views
2

角度2アプリケーションで角カレンダーを統合しましたが、jsonファイルからデータを取得しようとしているときにconsole.logにエラーが発生しました。 ERROR:あなたの方法でERROR SyntaxError:予期しないトークン:角度2の位置6のJSONで

ERROR SyntaxError: Unexpected token : in JSON at position 6 
    at Object.parse (<anonymous>) 
    at Response.Body.json (http.es5.js:796) 
    at MapSubscriber.project (events.service.ts:15) 
    at MapSubscriber._next (map.js:77) 
    at MapSubscriber.Subscriber.next (Subscriber.js:89) 
    at XMLHttpRequest.onLoad (http.es5.js:1205) 
    at ZoneDelegate.webpackJsonp.706.ZoneDelegate.invokeTask (zone.js:398) 
    at Object.onInvokeTask (core.es5.js:4116) 
    at ZoneDelegate.webpackJsonp.706.ZoneDelegate.invokeTask (zone.js:397) 
    at Zone.webpackJsonp.706.Zone.runTask (zone.js:165) 
    at XMLHttpRequest.ZoneTask.invoke (zone.js:460) 

フルcalendar.component.ts

export class FullCalendarComponent implements OnInit { 

    getEvent:object; 

    constructor(private eventsService:EventsService){} 

    ngOnInit(){ 

     this.eventsService.getEvents().subscribe(getEvent => this.getEvent = getEvent); 
    } 
} 

events.service.ts

import { Injectable } from '@angular/core'; 
import { Http } from '@angular/http'; 
import 'rxjs/add/operator/map'; 

@Injectable() 
export class EventsService { 

    constructor(private http: Http) { } 
    getEvents() 
    { 

    return this.http.get('src/assets/data/events.json').map(response => response.json().data); 

    } 
} 

events.json

{ 
    "date": [ 
      { 
      "title": "All Day Event", 
      "start": "2017-04-01" 
      } 
     ] 
} 

答えて

2

ルックあなたが使っているサービスでdataプロパティと返信が返されます。date

getEvents() 
    { 

    return this.http 
        .get('src/assets/data/events.json') 
        .map(response => response.json().date);//////////////////////////// 

    } 
関連する問題