安卓:解析特殊字符(ä,ö,ü)的JSON特殊字符、JSON

2023-09-13 02:06:32 作者:残留的温柔。

有人可以帮助我,如何解析特殊字符JSON?而且因为我正在做一个德国应用程序,它包含了大量的特殊字符,如ä,ö,ü,ß。有谁能告诉我如何通过展示JSON解析这些字符?现在他们只显示为?

Can someone help me, how to parse special characters in JSON? And since I'm making a German App, it includes a lots of special characters like ä,ö,ü,ß. Can somebody tell me how to show those characters through parsing JSON? Right now they are only shown as '?'

下面是我的JSON解析方法:

Here's my JSON parsing method:

void examineJSONFile()
    {
        try
        {
            String y = "";
            InputStream is = this.getResources().openRawResource(R.raw.json);
            Writer writer = new StringWriter();
            char[] buffer = new char[1024];

            try {
              BufferedReader reader = new BufferedReader(
                new InputStreamReader(is, "UTF-8")
              );
              int n;
              while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
              }
            } finally {
              is.close();
            }

            String jsontext = writer.toString();

            JSONArray entries = new JSONArray(jsontext);

            int j;
            for (j=0;j<entries.length();j++)
            {
                JSONObject post = entries.getJSONObject(j);
                y += post.getString("description") + "\n";
            }
            txt_beschreibung.setText(y);
        }
        catch (Exception je)
        {
            txt_beschreibung.setText("Error w/file: " + je.getMessage());
        }

    }

感谢你。

推荐答案

这样的字符必须为UTF-8编码最少。检查您的文件保存在本incoding。

Such chars must be in UTF-8 encoding at least. Check if your file is saved in this incoding.

 
精彩推荐