2017-04-15 88 views
2

我已经在角2应用程序中集成了角度完整日历,但是当我试图从持有事件列表的json文件中获取数据时,在console.log中获取错误。 错误:错误语法错误:意外的标记:在角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);//////////////////////////// 

    } 
相关问题