如何从JSON对象中删除转义字符?

时间:2019-04-26 12:51:10

标签: node.js json replace escaping sails.js

我已经构建了一个API以从数据库获取数据,但是它在附件数据中添加了转义字符。如何删除此反斜杠?

这是我的API代码

QueryGenerator.getEventList(req.user.dbName, req.user.teacherId, req.body.limit, req.body.skip, req.body.dateStart||'', req.body.dateEnd||'')
  .then(result=>{
    res.ok(result);
  }).catch(error=>{
  console.log(error);
  res.ok({message: 'Something went wrong', error: error},"ERROR","ERROR");
})

它在邮递员中给出了这些结果

{
    `"code": "OK",`
    `"message": "Operation executed successfully",
`
    `"data": [
 {
            "id": 11,
            "events": "sasasa",
            "edate": "20-03-2019",
            "detail": "asasasa",
            "class_id": "7",
            "attachment": "\"\"",
            "noticetype": "sasasa",
            "youtubeurl": "",
            "addedon": "1556197002625"
        },
        {
            "id": 12,
            "events": "C6f6g5",
            "edate": "25-04-2019",
            "detail": "Gctctc",
            "class_id": "40",
            "attachment": "[{\"attachment\":\"http://www.example.com/xyz/abc/abc/qwerty.jpg\"},{\"attachment\":\"http://www.example.com/abc/abc/abc/xyz.jpg\"}]",
            "noticetype": "section",
            "youtubeurl": "",
            "addedon": "1556194761807"
        }
    ]`
}

0 个答案:

没有答案