1

I want to encode only Chinese string to unicode string on android.

for example, it need to change {"city" = "中国 辽宁 沈阳", name = "User1"} to string of {"city" = "\ue600\ue603\ue705\ue355\ue703", name = "User1"} format on android.

please help me.

Jhanvi
  • 5,069
  • 8
  • 32
  • 41
Linda
  • 49
  • 1
  • 6
  • Why do you want to convert it to unicode? What will you do with your json once the text will be converted? – lcw_gg Mar 13 '15 at 10:29
  • @Linda Fortunately (unfortunately?) Java's string length is number of code units, not _characters_. It means that `"中国 辽宁 沈阳"` doesn't necessarily have length of 8 characters (see also [this post](http://stackoverflow.com/a/27229590/1207195) for more details). Java's string are UTF-16 encoded then simply looping through each character you'll have each code unit. Format each `Char` as hex number, prepend `\u` and join everything all together. – Adriano Repetti Mar 13 '15 at 10:38

0 Answers0