最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - json parse - unescaping the quotes - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 6

What 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)

发布评论

评论列表(0)

  1. 暂无评论