2013-05-09 52 views
0

我試圖從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()); 
       } 

回答

0

檢查您的logcat ....它顯示相同的響應或顯示正確的字符?

+0

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

+0

然後我認爲你應該在Web服務器端進行一些解析,比如用''替換'£' – user1575100 2013-05-09 13:44:35