I encountered an issue with the following error message:
ERROR SyntaxError: Unexpected token
in JSON at position 508
. I am seeking clarification on this matter and would appreciate any assistance in identifying where I may be making a mistake.
Below is the getpack
function:
getpacks(): Packs[] {
this.dataSource.getpacks().subscribe(packList => this.packList = packList);
console.log('"repository"');
console.log(this.packList);
console.log(JSON.parse(JSON.stringify(this.packList))) ;
return this.packList;
Here is the function responsible for HTTP calls:
getpacks(): Observable<Packs[]> {
console.log('rest');
return this.http.request(new Request({
method: RequestMethod.Post,
url: '/Dev/getPack',
body: {
'ownerID': 1001,
'outputMsgFlag' : '',
'outputMSg' : ''
},
headers: this.headers,
})).map(response => response.json());
}
This function retrieves values and assigns them to packList:
get packList(): Packs[] {
return this.repository.getpacks();
}
Displayed below is the JSON data:
{
"packList": [
{
"pack_id": 1,
"pack_name": "Bangalore Janapriyaa",
"pack_type": "base pack",
"base_price": 124,
"cgst_amount": 11.16,
"sgst_amount": 11.16,
"total_tax": 22.32,
"total_amount": 146.32,
"active": "Y",
"created_on": "2016-09-20 14:49:00.0",
"created_by": "Abhishek",
"owner_id": 1001,
"modified_on": "2016-09-27 08:29:00.0",
"modified_by": "Dynabox",
"disabled_on": "",
"comments": "My name is Scott Chow\r"
},
{
"pack_id": 2,
"pack_name": "Vijaynagar Janapriya",
"pack_type": "base pack",
"base_price": 128,
"cgst_amount": 11.52,
"sgst_amount": 11.52,
"total_tax": 23.04,
"total_amount": 151.04,
"active": "Y",
"created_on": "2017-01-05 04:18:00.0",
"created_by": "Abhishek",
"owner_id": 1001,
"modified_on": "2017-06-14 11:51:00.0",
"modified_by": "Zoombox",
"disabled_on": "",
"comments": "and I am going to be your guide on this journey to building a successful blog. I have been building blogs and websites since 2002.\r"
}
]
}
The error I am facing is detailed below. Kindly review it and provide any possible solutions:
core.es5.js:1020 ERROR SyntaxError: Unexpected token
in JSON at position 508
at Object.parse (<anonymous>)
at Response.webpackJsonp.../../../http/@angular/http.es5.js.Body.json (http.es5.js:797)
at MapSubscriber.project (rest.datasource.ts:95)
at MapSubscriber.webpackJsonp.../../../../rxjs/operator/map.js.MapSubscriber._next (map.js:77)
at MapSubscriber.webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.next (Subscriber.js:89)
at XMLHttpRequest.onLoad (http.es5.js:1226)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)
at Object.onInvokeTask (core.es5.js:3881)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:424)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (zone.js:192)
defaultErrorLogger @ core.es5.js:1020
webpackJsonp.../../../core/@angular/core.es5.js.ErrorHandler.handleError @ core.es5.js:1080
next @ core.es5.js:4503
schedulerFn @ core.es5.js:3635
webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:238
webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.next @ Subscriber.js:185
webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber._next @ Subscriber.js:125
webpackJsonp.../../../../rxjs/Subscriber.js.Subscriber.next @ Subscriber.js:89
webpackJsonp.../../../../rxjs/Subject.js.Subject.next @ Subject.js:55
webpackJsonp.../../../core/@angular/core.es5.js.EventEmitter.emit @ core.es5.js:3621
(anonymous) @ core.es5.js:3912
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:392