Arrays &引用;JSON中位置139处的意外标记}”;错误消息
当我运行像这样的angular代码时,出现了一些问题:Arrays &引用;JSON中位置139处的意外标记}”;错误消息,arrays,json,angular,subscription,angular5,Arrays,Json,Angular,Subscription,Angular5,当我运行像这样的angular代码时,出现了一些问题: { Items: [ { text: [Object], description: [Object], id: [Object], userid: [Object], title: [Object] }, { text: [Object], description: [Object], id: [Object], userid: [Object], title
{ 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 }
返回这个.http.get('apirl').map(res=>resas 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获取数据,但我的页面上显示了错误消息:
“位置139处JSON中的意外标记}”
我可以在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",
}
]
[
{
“标题”:“fakfjdskaf”,
“说明”:“fdkalfjdskalfj”,
“文本”:“dkalfjdsklafjdksalfjsda
”,
“用户ID”:“100”,
“id”:“13”,
}
, {
“头衔”:“头衔”,
“说明”:“说明”,
“文本”:“AAAA”,
“userid”:“userid”,
“id”:“100”,
}
, {
“头衔”:“铁匠”,
“说明”:“说明”,
“文本”:“文本”,
“用户ID”:“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"
}
]
[
{
“标题”:“fakfjdskaf”,
“说明”:“fdkalfjdskalfj”,
“文本”:“dkalfjdsklafjdksalfjsda
”,
“用户ID”:“100”,
“id”:“13”
},
{
“头衔”:“头衔”,
“说明”:“说明”,
“文本”:“AAAA”,
“userid”:“userid”,
“id”:“100”
}
, {
“头衔”:“铁匠”,
“说明”:“说明”,
“文本”:“文本”,
“用户ID”:“di”,
“id”:“12”
}
]
您能将实际的json字符串和其他代码放在出现错误的地方吗?看起来http调用返回的json可能有问题。你能把JSON也放进去吗?试试(res=>res.JSON()作为Article[])@GaurangDave我添加了我的代码和数据,请检查:这不是有效的JSON。使用JSON感知编辑器(而不是JavaScript编辑器!)或JSON验证器(即,查看任何一个免费的在线JSON验证站点)——也就是说,现有的工具/资源可以帮助确定数据中的错误,请使用它们!谢谢,这就是问题所在!你很好,本