JSONObject in org.json lib: utf-8 encoding issue -
i'm following unicode - how characters right? post.
the issue have jsonobject encoding (i'm using org.json
lib).
the issue arises when put string àòùè쀀
, example, in jsonobject.
system.out.println(entry.getvalue()); jsonobject temp = new jsonobject(); temp.put("values", entry.getvalue(); system.out.println(temp.tostring());
i obtain àòùè쀀
, {"values":"àòùèì\u20ac\u20ac"}
instead of {"values":"àòùè쀀"}
.
edit
by passing hashtable jsonobject, extended utf-8 encoding used. example, hashtable
{€èòàùì€ù=èòàù€ì, €òàèùì€=èòàù€ìç§$}
becomes jsonobject
{"\u20acòàèùì\u20ac":"èòàù\u20acìç§$","\u20acèòàùì\u20acù":"èòàù\u20acì"}
they equal, unicode escaping taking bit more space. writing \u004a
in java same writing a
. if correctness concern, doesn't matter.
and won't take considerable amount of space either unless of text between 0x2000 - 0x20ff:
the following code escapes c0 , c1 control characters, escapes 0x2000 - 0x20ff:
if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) {
so character between 0x2000 - 0x20ff , control characters represented unicode escapes. makes sense control characters because not allowed in json in unescaped form.
as 0x2000 - 0x20ff, have no idea because code not commented. every character unescaped in range valid json. of course, 0x2028
, 0x2029
not valid in javascript (so small detail makes json syntax not subset of javascript syntax), it's idea escape in json in case being used jsonp javascript really. not apparent me why code escapes whole range because 2 characters in range illegal.
Comments
Post a Comment