Hi, On Nov 21, 3:01 pm, tom tomsen <[email protected]> wrote: > On Windows XP with Internet Explorer 8, I came across the following > situation. (http://jsfiddle.net/tCKrt/) > > var data = {name: 'öäöä'}; > Object.toJSON(data); > > Every Browser returns "öäöa" except IE8 returns (something like) > "\u080\u898".
(Specifically, "\u00f6\u00e4\u00f6\u00e4".) It comes to the same thing, "öäöä" and "\u00f6\u00e4\u00f6\u00e4" are *exactly* the same string. The latter is written with Unicode escape sequences, the former with literal Unicode characters. Check this out: http://jsbin.com/ecojun On Chrome, you see this: * * * * d1.name: öäöä {"name":"öäöä"} d2.name: öäöä d1.name === d2.name? true * * * * On IE8, you see this: * * * * d1.name: öäöä {"name":"\u00f6\u00e4\u00f6\u00e4"} d2.name: öäöä d1.name === d2.name? true * * * * Note the last line. > To fix that Problem I had to modify Object::stringify(): > > function stringify(object) { > var string = JSON.stringify(object); > return unescape(string.replace(/\\u/g, '%u')); > } Well first, there is no problem, and thus no need for a fix. :-) IE8 just uses escape sequences rather than literal characters. But secondly, your fix will tend to mess up anything in your string that starts with a '%' and is followed by 2-4 hex digits. Separately, `escape` and `unescape` were deprecated years ago and shouldn't be used. If you really, really want to use Unicode literals, you'd want: function stringify(object) { var string = JSON.stringify(object); return string.replace(/\\u([0-9A-Za-z]{2,4})/g, function(m, c0) { return String.fromCharCode(parseInt(c0, 16)); }); } ...or similar. HTH, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
