While working with my Json file, I encountered an error that has been validated on https://jsonlint.com/
@Injectable()
export class LightParserService{
ITEMS_URL = "./lights.json";
constructor(private http: Http) {
}
getItems(): Promise<Light[]> {
return this.http.get(this.ITEMS_URL).toPromise()
.then(resp => {
return resp.json() as Light[];
});
}
}
However, when I try to use my function in another component:
lights : Light[] = [];
getLights(): void{
this.lightService.getItems().then(light => this.lights = light);
}
Upon visiting my website, I am faced with the following error message: Error: Uncaught (in promise): SyntaxError: Unexpected token < in JSON at position 0
I am perplexed by this issue. The JSON file is valid and the fields in my Light object are correct. Can someone help me resolve this?