Android用中文解析Json

时间:2012-01-26 14:53:39

标签: android json

我有一个有效的Json字符串(至少我尝试过的每个在线验证器都是这样),其中包含一些中文字符。

json字符串如下:

{ “标题”: “\ u8981 \ u805e - \ u83ef \ u723e \ u8857 \ u65e5 \ u5831”, “URL”: “http://cn.wsj.com”, “降序”:“\ u300a \ u83ef \ u723e \ u8857 \ u65e5 \ u5831 \ u300b \ u4e2d \ u6587 \ u7db2 \ u7d61 \ u7248 \ u6700 \ u65b0 \ u8ca1 \ u7d93 \ u8981 \ u805e”, “IMAGEURL”:空, “LASTUPDATE”: “1327588937”, “项”:[{ “标题”:“\ u4e16 \ u8cbf \ u7d44 \ u7e54 \ u7e3d \ u5e79 \ u4e8b \ ufe55 \ u4eba \ u6c11 \ u5e63 \ u5e63 \ u503c \ u88ab \ u4f4e \ u4f30 \ ufe50 \ u4f46 \ u4f4e \ u4f30 \ u7a0b \ u5ea6 \ u4e0d \ u660e “ ”说明“:” \ u4e16 \ u754c \ u8cbf \ u6613 \ u7d44 \ u7e54 \ u7e3d \ u5e79 \ u4e8b \ u5e15 \ u65af \ u5361 \ u723e \ uff0e \ u62c9 \ u7c73 \ u9031 \ u56db \ u8868 \ u793a \ ufe50 \ u4eba \ u6c11 \ u5e63 \ u532f \ u7387 \ u88ab \ u660e \ u986f \ u4f4e \ u4f30 \ ufe50 \ u4f46 \ u4f4e \ u4f30 \ u7a0b \ u5ea6 \ u9084 \ u4e0d \ u6e05 \ u695a \ u3002 ”, “URL”: “http://cn.wsj.com/big5/20120126/BCHc-20120126WR182711424.asp?source=rss”, “pubdate的” 日期null}]}

现在,当我通过新的JsonObject(jsonString)解析Android中的JsonString时,我只得到一些正方形而不是字符。

为什么android不能处理这个json字符串?

任何帮助都会被贬低。

如果有人想拥有服务器Ressource,可以在以下网址找到:

//编辑 网址已删除

2 个答案:

答案 0 :(得分:0)

当您收到JSON时,您可能必须在构建结果时解码UTF-8结果。看看utf8解码。类似于this, but with JSON

的东西

答案 1 :(得分:0)

public static String test(){
    String testResult= "";
    try {
        HttpGet get = new HttpGet("http://xxxxx");//edit url removed.
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(get);
        String result = EntityUtils.toString(response.getEntity());
        JSONObject obj = new JSONObject(result);
        if(!obj.isNull("title")){
            testResult= obj.getString("title");
            Log.d("Test","Test1:"+ testResult);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return testResult;//
}

然后TextView.setText(testResult); 这个对我有用。

这是繁体中文字符串:“要闻 - 华尔街日报” 可能是你的ROM没有繁体中文字体????

相关问题