【问题标题】:Create JSON without backslash创建不带反斜杠的 JSON
【发布时间】:2018-12-06 09:32:44
【问题描述】:

我将 JSON 发送到我的后端并将其保存在我的数据库中,但在我的 JSON 数据中,我有一些 \ 字符。如何在没有这些反斜杠的情况下保存我的 JSON?

 survey.onComplete.add(function(result) {
   try {

     const response = ResultService.saveSurveyResult({
       result: (document.querySelector("#surveyResult").innerHTML = JSON.stringify(result.data)),
       UserId: UserId,
       SurveyId: 1
     });

这是我保存在数据库中的 JSON:

"{\"customerName\":\"jhkghjgh\",\"birthdate\":\"05.06.1990\"}"

这是我要保存的:

{"customerName":"jhkghjgh","birthdate":"05.06.1990"}

这是我的后端代码:

async saveSurveyResult (req, res) {
  try {
    const surveyResult = await SurveyResult.create(req.body)

    const surveyResultJson = surveyResult.toJSON()

    res.send({
      surveyResult: surveyResultJson
    })

【问题讨论】:

  • req.body 包含什么?
  • req.body 包含调查的结果(result: (document.querySelector("#surveyResult").innerHTML = JSON.stringify(result.data)), )

标签: javascript json vue.js


【解决方案1】:

我刚刚删除了创建字符串的部分。所以这很好用:

 try {

    const response = ResultService.saveSurveyResult({
      result: result.data,
      UserId: UserId,
      SurveyId: 1
    });

【讨论】:

    猜你喜欢
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 2017-10-01
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 2019-05-05
    相关资源
    最近更新 更多