"Unexpected token } in JSON at position 139" 错误信息

"Unexpected token } in JSON at position 139" error message

当我 运行 一些像这样的 angular 代码时发生了一些问题:

return this.http.get('apiurl').map(res => res as Article[]);

当我检查我的 cloudwatch 时,我发现我的日志是这样的:

    { Items: 
[ { text: [Object],
    description: [Object],
    id: [Object],
    userid: [Object],
    title: [Object] },
    { text: [Object],
    description: [Object],
    id: [Object],
    userid: [Object],
    title: [Object] },
    { text: [Object],
    description: [Object],
    id: [Object],
    userid: [Object],
    title: [Object] } ],
    Count: 3,
    ScannedCount: 3 }

我想这意味着我可以从 DynamoDB 获取数据,但我的页面上显示错误消息:

"Unexpected token } in JSON at position 139"

我可以在 codepen 上毫无错误地获取我的数据。 我检查了很多,仍然无法弄清楚哪里出了问题。谁能帮我解决这个问题?任何回复都将有义务

服务代码

 getArticleById(id:string){
        this.dataLoaded.next(null);
        this.dataLoadFailed.next(false);
       return this.http.get('https://example.com/'+id)
           .map(res => res as Article[]);
    }

在其他页面上调用的服务:

articles:Article[] = [];

getAllArticles(){
    this.articleService.getArticleById('all')
        .subscribe((articles:Article[])=>{
      this.articles = articles;
    })
  }

这是我通过codepen得到的数据:

[
 {
  "title" : "fakfjdkfjdskaf",
  "description" : "fdkalfjdskalfj",
  "text" : "<p>dkalfjdsklafjdksalfjsda</p><p><br></p>",
  "userid" : "100",
  "id" : "13",
} 
, {
  "title" : "title",
  "description" : "desc",
  "text" : "aaaaa",
  "userid" : "userid",
  "id" : "100",
} 
, {
  "title" : "tiel",
  "description" : "desc",
  "text" : "text",
  "userid" : "di",
  "id" : "12",
} 
]

您的 json 字符串有误。它在最后一个元素有额外的逗号 (,)。

正确json

[
 {
  "title" : "fakfjdkfjdskaf",
  "description" : "fdkalfjdskalfj",
  "text" : "<p>dkalfjdsklafjdksalfjsda</p><p><br></p>",
  "userid" : "100",
  "id" : "13"
},
{
  "title" : "title",
  "description" : "desc",
  "text" : "aaaaa",
  "userid" : "userid",
  "id" : "100"
} 
, {
  "title" : "tiel",
  "description" : "desc",
  "text" : "text",
  "userid" : "di",
  "id" : "12"
} 
]