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 回答