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)