英文:
How to remove double quotes from json object type JSON value with remove "\r\n \ " tried many times
问题
Expected :
[{"MetaId":4,"FilePrefix":" as- apt05 - 04 - 2023", "RequestjView":{ "article": {"article_doi": "10.1139/cgj-2022-44441","data": null},"RequestID": "SCP2304110002"} }]
英文:
Problem :
[{"MetaId":4,"FilePrefix":" as- apt05 - 04 - 2023", "RequestjView":"{ \r\n "article": {\r\n "article_doi": "10.1139/cgj-2022-44441",\r\n "data": null\r\n },\r\n "RequestID": "SCP2304110002"\r\n}"}]
Expected :
[{"MetaId":4,"FilePrefix":" as- apt05 - 04 - 2023", "RequestjView":{ "article": {"article_doi": "10.1139/cgj-2022-44441","data": null},"RequestID": "SCP2304110002"} }]
答案1
得分: 1
如果我们将这些数据存储在一个变量中,那么变量名就是rawData,代码部分如下:
let rawData = '[{"MetaId":4,"FilePrefix":"as-apt05-04-2023","RequestjView":"{ \r\n \"article\": {\r\n \"article_doi\": \"10.1139/cgj-2022-44441\",\r\n \"data\": null\r\n },\r\n \"RequestID\": \"SCP2304110002\"\r\n}"}]';
/* 替换这些字符:\r、\n、\、"{ 和 }" */
rawData = rawData.replace(/\\n/g, '').replace(/\\r/g, '').replace(/\\/g, '').replace(/\"{/g, '{').replace(/\}"/g, '}');
/* 将其转换为对象 */
var dataaF = JSON.parse(rawData);
/* 使用alert可以查看转换后的数据 */
alert(dataaF[0].RequestjView);
只返回代码部分的翻译。
英文:
If we take this data in a variable then variable name is rawData and
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
let rawData = '[{"MetaId":4,"FilePrefix":" as- apt05 - 04 - 2023", "RequestjView":"{ \r\n "article": {\r\n "article_doi": "10.1139/cgj-2022-44441",\r\n "data": null\r\n },\r\n "RequestID": "SCP2304110002"\r\n}"}]';
/* replace these from \r, \n, \, "{ and }" */
rawData = rawData.replace(/\\n/g, '').replace(/\\r/g, '').replace(/\\/g, '').replace(/\"{/g, '{').replace(/\}"/g, '}');
/* convert it in object */
var dataaF = JSON.parse(rawData);
/* help of alert you can see the converted data */
alert(dataaF[0].RequestjView);
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论