如何在 javascript 中从我的 Json 中删除?

我正在尝试将 json 注入到我的 backbone.js 应用程序中。

有什么办法能让我移除这个吗?
下面是我提供的一个例子:

[{"Id":1,"Name":"Name}]
150645 次浏览

Presumably you have it in a variable and are using JSON.parse(data);. In which case, use:

JSON.parse(data.replace(/"/g,'"'));

You might want to fix your JSON-writing script though, because " is not valid in a JSON object.

Accepted answer is right, however I had a trouble with that. When I add in my code, checking on debugger, I saw that it changes from

result.replace(/"/g,'"')

to

result.replace(/"/g,'"')

Instead of this I use that:

result.replace(/(&quot\;)/g,"\"")

By this notation it works.

var data = $('<div>').html('[{&quot;Id&quot;:1,&quot;Name&quot;:&quot;Name}]')[0].textContent;

that should parse all the encoded values you need.

The following works for me:

function decodeHtml(html) {
let areaElement = document.createElement("textarea");
areaElement.innerHTML = html;


return areaElement.value;
}

i used replace feature in Notepad++ and replaced &quot; (without quotes) with " and result was valid json

In my case "quot" was replaced with other characters so I found a stupid but working workaround

str.replace(/&qu/g,'').replace(/ot\;/g,'')

This is a simple way to replace &quot with what you need to change it - chars, strings etc.

function solve(input) {
const replaceWith = '"' // e.g. replace &quot; by "
const result = input.replace(/&quot;/g, replaceWith)
return result;
}


console.log(solve('{&quot;x&quot;:&quot;1&quot;,&quot;y&quot;:&quot;2&quot;,&quot;z&quot;:&quot;10&quot;}')
   

IF you are using SQL then you can use:

update tablename set payload = replace(payload, '&', chr(39)) where id = 'unique id';

If you are using python then you can use:

import html
l = [{&quot;Id&quot;:1,&quot;Name&quot;:&quot;Name}]
r = html.unescape(l)