jetti777Ltd / mochiweb

Automatically exported from code.google.com/p/mochiweb
Other
0 stars 0 forks source link

mochijson:decode() \u00e9 etc. #45

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
1> mochijson:encode("\303\251").
[34,"\\u00c3","\\u00a9",34]

2> mochijson:decode([34,"\\u00c3","\\u00a9",34]).
"\303\251"

and we can see input in (1) and output in (2) is equal, it is good,
but i am wait for "\u00e9"

see next example
====================================

3> mochijson:encode(<<"\303\251">>).
[34,"\\u00e9",34]

4> mochijson:decode([34,"\\u00e9",34]).
"\351"

ok, we get in (3) "\u00e9" but(!) input (1) not equal output (4)!!! - it is 
bad :(((

The difference is not-binary and binary input form and
in my case it will work properly with mochijson2, but...

I need form {struct, []}, {array, []} and I cannot get it work with
mochijson2 :-(

Please, tell me what can I do to solve this trouble?..

Thx.

Original issue reported on code.google.com by vinn...@gmail.com on 6 Oct 2009 at 2:43

GoogleCodeExporter commented 8 years ago
and maybe you now howto handle with {struct, []} member to do it atom (now it 
is string 
in response)

Original comment by vinn...@gmail.com on 6 Oct 2009 at 2:45

GoogleCodeExporter commented 8 years ago
mochijson decodes to unicode code points, not to UTF-8, so what you want is not 
possible. When it encodes 
a binary as a string (by default) it considers it to be UTF-8 because binaries 
only contain octets, but when it 
encodes a list it assumes it to be unicode code points.

You need to change your code to use mochijson2 if you want UTF-8 in both 
directions. mochijson will never 
return atoms directly because that can cause a leak in the atom table.

The library is doing exactly what it's supposed to do in this case, if you need 
help you might want to try the 
google group.

Original comment by bob.ippo...@gmail.com on 6 Oct 2009 at 2:53

GoogleCodeExporter commented 8 years ago
I written small wrapper to handle this trouble

it can be used by

json:decode(Json).

see attach

Original comment by vinn...@gmail.com on 6 Oct 2009 at 6:32

GoogleCodeExporter commented 8 years ago
new version of my wrapper with encode and decode function

Original comment by vinn...@gmail.com on 7 Oct 2009 at 7:48

Attachments: