问题遇到的现象和发生背景
这是后端django发送的数据,xml_list是数组,里面存的字符串,数组里面的字符串可能存在不定个数的单引号或者双引号
问题相关代码,请勿粘贴截图
data={
'status':200,
'filename': file_name,
'appid':appid,
'key':appidkey,
'from':myfrom,
'to':to,
'text_list':xml_list,
}
return render(request,"transprocess.html",{'data':json.dumps(data),"trans_count": trans_count})
前端接收
var d = '{{ data | safe}}';
// console.log(JSON.parse(d));
data = JSON.parse(d);
在这里就报错了,没法解析
运行结果及报错内容
text_list只截取了一个内容,这一个内容出现了两个“” "11011.",然后就报错了
{"status": 200, "filename": "p111-book-huangbin__katsunari-okamoto-fundamentals_of_op_74-175_30-59_1-5-auto-zh.docx", "appid": "20210106000664590", "key": "lBy1rXG61iBcVfiIEsNd", "from": "auto", "to": "zh", "text_list": ["Figure Several pulse waveforms with PCM code of "11011." (a) Input pulse waveform, (b) output pulse waveform after of the fiber with , and (c) output pulse after propagation."]}
我的解答思路和尝试过的方法
我尝试在后端把额外的“”变为中文的,这样虽然部分可以,但是还有其它问题,并不是个好方案,列表内容在python里面没问题,存在不定个数的单引号双引号,在js解析就会出问题
我想要达到的结果
能拿到所有的数据就行了