[英]How to remove double quotes from json object
My JSON object looks like below我的 JSON 对象如下所示
"{'EN':{'APP_TITLE':'TESTHEADING'}}"
Can some help me on removing the double quotes at first position and last position I tried with regex but not able to remove it.可以帮助我删除第一个位置和最后一个位置的双引号,我尝试使用正则表达式但无法删除它。
Use .substring()
like below:使用.substring()
如下:
let input = "\\"{'EN':{'APP_TITLE':'TESTHEADING'}}\\""; let output = input.substring(1, input.length - 1); console.log(`Input: ${input} \\nOutput: ${output}`);
1
skipping the first character) and an end (here str.length - 1
skipping the last)它需要一个开始索引(这里是1
跳过第一个字符)和一个结束(这里是str.length - 1
跳过最后一个字符)g
option replace all occurences of your target character ' => "
g
选项替换所有出现的目标字符' => "
Combining the 3 steps will give you something like this结合这 3 个步骤会给你这样的东西
const str = "\\"{'EN':{'APP_TITLE':'TESTHEADING'}}\\""; const withoutQuotes = str .substring(1, str.length - 1) .replace(/'/g, '"'); const actualJSON = JSON.parse(withoutQuotes); console.log(actualJSON);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.