簡體   English   中英

Android用中文字符解析Json

[英]Android parse Json with chinese characters

我得到了一個有效的Json字符串(至少我嘗試過的每個onlinevalidator都這樣說),其中包含一些漢字。

json字符串如下:

{“ title”:“ \\ u8981 \\ u805e-\\ u83ef \\ u723e \\ u8857 \\ u65e5 \\ u5831”,“ url”:“ http://cn.wsj.com”,“ desc”:“ \\ u300a \\ u83ef \\ u723e \\ u8857 \\ u65e5 \\ u5831 \\ u300b \\ u4e2d \\ u6587 \\ u7db2 \\ u7d61 \\ u7248 \\ u6700 \\ u65b0 \\ u8ca1 \\ u7d93 \\ u8981 \\ u805e“,” imageUrl“:null,” lastUpdate“:” 1327588937“,” items :[{“ title”:“ \\ u4e16 \\ u8cbf \\ u7d44 \\ u7e54 \\ u7e3d \\ u5e79 \\ u4e8b \\ ufe55 \\ u4eba \\ u6c11 \\ u5e63 \\ u5e63 \\ u503c \\ u88ab \\ u4f4e \\ u4f30 \\ ufe50 \\ u4 \\ 4 \\ u5ea6 \\ u4e0d \\ u660e“,” desc“:” \\ u4e16 \\ u754c \\ u8cbf \\ u6613 \\ u7d44 \\ u7e54 \\ u7e3d \\ u5e79 \\ u4e8b \\ u5e15 \\ u65af \\ u5361 \\ u723e \\ uff0e \\ u62c9 \\ u8868 \\ u793a \\ ufe50 \\ u4eba \\ u6c11 \\ u5e63 \\ u532f \\ u7387 \\ u88ab \\ u660e \\ u986f \\ u4f4e \\ u4f30 \\ ufe50 \\ u4f46 \\ u4f4e \\ u4f30 \\ u7a0b \\ u5ea6 \\ u9084 \\ u4e0' url“:” http://cn.wsj.com/big5/20120126/BCHc-20120126WR182711424.asp?source=rss“,” pubdate“:null}]}

現在,當我通過新的JsonObject(jsonString)在Android中解析JsonString時,我只有一些正方形而不是字符。

為什么Android無法處理此json字符串?

任何幫助將不勝感激。

如果有人想擁有服務器資源,可以在以下位置找到它:

//刪除網址

收到JSON時,在構建結果時可能必須解碼UTF-8結果。 看看utf8解碼。 類似,但帶有JSON

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沒有繁體中文字體????

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM