我正在获取API的以下JSON:
{
"things": [
{
"id": 100,
"bla": "blablablabla",
"summary": "blablablabla",
"date": "11/12/2016",
},
{
"id": 101,
"bla": "blablablabla",
"summary": "blablablabla",
"date": "02/05/2017",
},
{
"id": 102,
"bla": "blablablabla",
"summary": "blablablabla",
"date": "03/03/2017",
},
{
"id": 103,
"bla": "blablablabla",
"summary": "blablablabla",
"date": "12/04/2017",
}
]
}
如您所见,此json中有一个错字,因为日期之后的逗号是错误的,有一种方法可以在每个日期之后删除此逗号?
最佳答案
替换逗号字符,后跟换行符和空格字符,后跟}
str.replace(/,(?=[\n\s]+})/g, "")