从字符串中删除 html 实体以修复 JSON 错误中的意外标记

Removing html Entities from string to fix Unexpected token in JSON ERROR

如何删除所有“\n”和空格以及“ ”之类的内容:

我试过了,但没有成功:x.replace(/\/g, '').replace(' ', '').replace('\n', '');

使用正则表达式

console.log( x.replace(/(&nbsp;|<([^>]+)>)/ig, "") );

 var x = `{    \n    \"formType\":\"CreateCaseRequest\",\n    \"documentID\":270550224,\n    \"documentRev\":\"1\",\n    \"formVersion\":\"v1\",\n    \"createdDateTime\":\"2019-03-25T13:31:44.216+0000\",\n    \"documentStatus\":\"Draft\",\n    \"documentTitle\":\n    {\n    },\n    \"documentSynopsis\":\n    {\n    },\n    \"highPriority\":false,\n   }`

console.log( x.replace(/(&nbsp;|<([^>]+)>)/ig, "") );

试试这个。

x.replace("\n", "\n");