get raw UTF8 data out of JSON.stringify?

6.167 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Egor Egorov

ungelesen,
10.06.2010, 08:38:3010.06.10
an nodejs
Hi!

I need to get raw UTF-8 data out of JSON.stringify, without the \uXXXX
escaped sequences. How do I do that?

var sys = require('sys');
var struct = ['вася'];
var json_string = JSON.stringify(struct);
sys.debug(json_string);

It returns "DEBUG: ["\u0432\u0430\u0441\u044f"]" and I want "DEBUG:
["вася"]".

Akzhan Abdulin

ungelesen,
10.06.2010, 08:58:0110.06.10
an nod...@googlegroups.com
You can do this after stringification using string 

json_string.replace(/\\u\d\d\d\d/g, function(a)
{
  // here convert sequence to correspond character.
});

2010/6/10 Egor Egorov <egor....@gmail.com>

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.


Jeff Lewis

ungelesen,
10.06.2010, 16:20:0510.06.10
an nodejs
You could do something like:

...
sys.debug(unescape(json_string.replace(/\\u/g, '%u'));

Jeff

On Jun 10, 5:58 am, Akzhan Abdulin <akzhan.abdu...@gmail.com> wrote:
> You can do this after stringification using string
>
> json_string.replace(/\\u\d\d\d\d/g, function(a)
> {
>   // here convert sequence to correspond character.
>
> });
>
> 2010/6/10 Egor Egorov <egor.ego...@gmail.com>
>
>
>
> > Hi!
>
> > I need to get raw UTF-8 data out of JSON.stringify, without the \uXXXX
> > escaped sequences. How do I do that?
>
> > var sys = require('sys');
> > var struct = ['вася'];
> > var json_string = JSON.stringify(struct);
> > sys.debug(json_string);
>
> > It returns "DEBUG: ["\u0432\u0430\u0441\u044f"]" and I want "DEBUG:
> > ["вася"]".
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nodejs" group.
> > To post to this group, send email to nod...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>
> > .

mario

ungelesen,
11.06.2010, 02:41:4211.06.10
an nodejs
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten