jetti777Ltd / mochiweb

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

mochijson2:encode strings to integer list strings #26

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
%mochijson2
mochijson2:encode({struct, [{"foo", foovalue}, {"bar", 3.2}]}).
% string result => {"foo":"foovalue","bar":3.2}

mochijson2:encode({struct, [{"foo", "foovalue"}, {"bar", 3.2}]}).
% string result => {"foo":[102,111,111,118,97,108,117,101],"bar":3.2}

%mochijson, with utf8 encoding. It bombed with unicode
Utf8 = mochijson:encoder([{input_encoding, utf8}]),
Utf8({struct, [{"foo", foovalue}, {"bar", 3.2}]}).
Utf8({struct, [{"foo", "foovalue"}, {"bar", 3.2}]}).
% string result => {"foo":"foovalue","bar":3.2}

not sure if this should be entered as a defect, or not but thought it was odd.

Original issue reported on code.google.com by john.m.b...@gmail.com on 1 Feb 2009 at 6:31

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Actually the utf8 is unnecessary for this case: 

%mochijson2
mochijson2:encode({struct, [{"foo", foovalue}, {"bar", 3.2}]}).
% string result => {"foo":"foovalue","bar":3.2}

mochijson2:encode({struct, [{"foo", "foovalue"}, {"bar", 3.2}]}).
% string result => {"foo":[102,111,111,118,97,108,117,101],"bar":3.2}

%mochijson
mochijson:encode({struct, [{"foo", foovalue}, {"bar", 3.2}]}).
mochijson:encode({struct, [{"foo", "foovalue"}, {"bar", 3.2}]}).
% string result => {"foo":"foovalue","bar":3.2}

Original comment by john.m.b...@gmail.com on 1 Feb 2009 at 6:34

GoogleCodeExporter commented 8 years ago
mochijson2 has a different API than mochijson, which is why it's a separate 
module. This is expected behavior, 
JSON strings in mochijson2 MUST be represented as binary, because there is no 
way to distinguish lists of 
integers and erlang strings (because erlang strings are just syntax sugar for 
lists of integers).

Original comment by bob.ippo...@gmail.com on 1 Feb 2009 at 6:39

GoogleCodeExporter commented 8 years ago
@Bob

Thank you, sorry for the false alarm!

Original comment by john.m.b...@gmail.com on 1 Feb 2009 at 3:16