在android中使用阿拉伯语文本

时间:2013-05-31 11:34:17

标签: java android

如何以json格式获取阿拉伯字符串以及如何在Android应用程序中显示 InputStreamReader中。我从服务器端获取json并使用Windows-1256 encodingString转换阿拉伯字符串,但某些文本没有正确显示。

HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            System.out.println(url + ":::url");
            try {
                HttpResponse httpResponse = httpClient.execute(httpGet);
                InputStream inputStream = httpResponse.getEntity()
                        .getContent();
                InputStreamReader inputStreamReader = new InputStreamReader(
                        inputStream,"windows-1256");
                        //new InputStreamReader(inputStream);
                BufferedReader bufferedReader = new BufferedReader(
                        inputStreamReader,8);
                StringBuilder stringBuilder = new StringBuilder();
                String bufferedStrChunk = null;
                while ((bufferedStrChunk = bufferedReader.readLine()) != null) {
                    stringBuilder.append(bufferedStrChunk);
                }

                return stringBuilder.toString();
            } catch (ClientProtocolException cpe) {
                System.out
                        .println("Exception generates caz of httpResponse :"
                                + cpe);
                cpe.printStackTrace();
            } catch (IOException ioe) {
                System.out
                        .println("Second exception generates caz of httpResponse :"
                                + ioe);

                ioe.printStackTrace();
            }

1 个答案:

答案 0 :(得分:1)

我一直是r& d大约一天,最后成功解析我的阿拉伯json响应从服务器使用以下代码。所以,可能对你有所帮助。

 HttpParams params = new BasicHttpParams();
 HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
 HttpProtocolParams.setContentCharset(params, "UTF-8");
 params.setBooleanParameter("http.protocol.expect-continue", false);
 HttpClient httpclient = new DefaultHttpClient(params);

 HttpPost httppost = new HttpPost(Your_URL);
 HttpResponse http_response= httpclient.execute(httppost);

 HttpEntity entity = http_response.getEntity();
 String jsonText = EntityUtils.toString(entity, HTTP.UTF_8);

 Log.i("Response", jsonText);

现在,使用jsonText来满足您的进一步要求。

谢谢