0

URL から JSON 応答を取得しようとしました。次のコードを使用しました。応答にフランス語の文字が含まれています。ブラウザでの応答は問題なく、文字が正しく表示されます。アプリで使うと、例えばこの「terminal_key」:「cl� Terminal」のように文字が違って見えます。

InputStream is = null;
                try {

                    DefaultHttpClient httpClient = new DefaultHttpClient();
                    HttpPost httpPost = new HttpPost("http://ptracker.com/webteh/localization.php");

                    HttpResponse httpResponse = httpClient.execute(httpPost);
                    HttpEntity httpEntity = httpResponse.getEntity();
                    is = httpEntity.getContent();          

                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                String json = null;
                try {
                    BufferedReader reader = new BufferedReader(new InputStreamReader(
                            is, "UTF-8"), 8);
                    StringBuilder sb = new StringBuilder();
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                    is.close();
                    json = sb.toString();
                    Log.v("json >>",json);
                } catch (Exception e) {
                    Log.e("Buffer Error", "Error converting result " + e.toString());
                }
4

1 に答える 1

0

logcat を確認してください....同じ応答を示していますか、それとも正しい文字を示していますか?

于 2013-05-09T10:56:42.830 に答える