解析URL中的法语字符时遇到问题

问题描述:

我试图从URL获取JSON响应。我使用了下面的代码。该响应包含法文字符。在浏览器中的回应是好的,它显示正确的字符。当我在应用程序中使用它时,字符看起来不同,例如像这样的“terminal_key”:“cl Terminal”。解析URL中的法语字符时遇到问题

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()); 
       } 

检查您的logcat ....它显示相同的响应或显示正确的字符?

+0

我得到了不同的回应,而不是正确的字符。 – Manikandan 2013-05-09 11:22:59

+0

然后我认为你应该在Web服务器端进行一些解析,比如用''替换'£' – user1575100 2013-05-09 13:44:35