【发布时间】: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