admin管理员组文章数量:1312782
so i am using json to pass some information from one place to another...
i have:
message.title = 'this is only a "test"';
so obviously, when i use JSON.stringify, i get escaped quotes.
What i want to know is, what is the best way to unescape those quotes when using JSON.Parse. i have:
var message = JSON.parse(message);
var original = ????;
var final = ????;
var regex = new RegExp(original, 'g');
for(var prop in message){
message.data[prop] = message.data[prop].replace(regex, final);
}
I wish to know if i am doing something wrong and, as i tried various values in 'original' and 'final', what are correct values for them.
Thank you
so i am using json to pass some information from one place to another...
i have:
message.title = 'this is only a "test"';
so obviously, when i use JSON.stringify, i get escaped quotes.
What i want to know is, what is the best way to unescape those quotes when using JSON.Parse. i have:
var message = JSON.parse(message);
var original = ????;
var final = ????;
var regex = new RegExp(original, 'g');
for(var prop in message){
message.data[prop] = message.data[prop].replace(regex, final);
}
I wish to know if i am doing something wrong and, as i tried various values in 'original' and 'final', what are correct values for them.
Thank you
Share Improve this question asked Aug 24, 2011 at 17:04 André Alçada PadezAndré Alçada Padez 11.6k26 gold badges71 silver badges128 bronze badges 2- What do you want to do with the parsed object? – Ray Toal Commented Aug 24, 2011 at 17:14
- thanks Ray, it is solved, it was my mistake – André Alçada Padez Commented Aug 24, 2011 at 17:20
1 Answer
Reset to default 6What i want to know is, what is the best way to unescape those quotes when using JSON.Parse
Do nothing. Parsing JSON will decode escapes. (If that doesn't work, then something is breaking between the data being converted to JSON and being parsed, or the data was bad to begin with)
本文标签: javascriptjson parseunescaping the quotesStack Overflow
版权声明:本文标题:javascript - json parse - unescaping the quotes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741835464a2400188.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论