Converting String to Android JSONObject loses utf-8

前端 未结 4 465
盖世英雄少女心
盖世英雄少女心 2021-01-06 02:12

I am trying to get a (JSON formatted) String from a URL and consume it as a Json object. I lose UTF-8 encoding when I convert the String to JSONObject.

This is The f

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-06 02:30

    You're telling Java to convert the string (with key message) to bytes using ISO-8859-1 and than to create a new String from these bytes, interpreted as UTF-8.

    new String(reader.getString("messages").getBytes("ISO-8859-1"), "UTF-8");
    

    You could simply use:

    String messages = reader.getString("messages");
    

提交回复
热议问题