小编Mic*_*art的帖子

Android Java UTF-8 HttpClient问题

我从一个网页抓取的JSON数组有奇怪的字符编码问题.服务器正在发送回此标头:

内容类型文本/ javascript; 字符集= UTF-8

此外,我可以查看Firefox或任何浏览器中的JSON输出,并正确显示Unicode字符.响应有时会包含来自其他语言的单词,带有重音符号等.但是当我把它拉下来并把它放到Java中的字符串时,我得到那些奇怪的问号.这是我的代码:

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

HttpGet httpget = new HttpGet("http://www.example.com/json_array.php");
HttpResponse response;
    try {
        response = httpclient.execute(httpget);

        if(response.getStatusLine().getStatusCode() == 200){
            // Connection was established. Get the content. 

            HttpEntity entity = response.getEntity();
            // If the response does not enclose an entity, there is no need
            // to worry about connection release

            if (entity != null) {
                // A Simple JSON Response Read
                InputStream instream …
Run Code Online (Sandbox Code Playgroud)

java android httpclient

16
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×1

httpclient ×1

java ×1