如何在json字符串android中删除??

时间:2015-04-29 03:14:08

标签: android json

每当我解析JSON字符串并在android Logcat中显示json输出的输出时,我总是找到

  

"家族。 PNG"

在Logcat中

。实际的字符串是" family.png"但它显示如上。知道如何解决这个问题吗?

这是JSON数据。

{"members": [
   {"user":"���d���e���8���8���f���5���c���7���3���7���1���4���7���6���6���f", "username":"���P���P���S���h���e���i���n", "avatar":"f������a������m������i������l������y������.������p������n������g"} 
    ]}

生成的JSON格式是Coldfusion。

{"members": [
<cfoutput query="getQry">
{"user":"#tuser#", "username":"#tusername#", "avatar":"#tpicture#"} <cfif currentrow LT getTrackQry.recordcount>,</cfif>
</cfoutput>
]}

这是从URL解析JSON对象。

public static JSONObject getFromUrl(String url) {
        InputStream is = null;
        String content = null;
        JSONObject jArray = null;
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = httpclient.execute(new HttpGet(url));
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
        }
        catch(Exception e){
            Log.e("log_tag", "Error in http connection " + e.toString());
        }

        try{
              BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf8"),8);
              StringBuilder sb = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) {
                  sb.append(line + "\n");
              }
              is.close();
              content = sb.toString();
        } catch(Exception e){
            Log.e("log_tag", "Error converting result " + e.toString());
        }

        try {
            jArray = new JSONObject(content);
        } catch (JSONException e){
            Log.e("log_tag", "Error parsing data " + e.toString());
        }           

        return jArray;      
    }

2 个答案:

答案 0 :(得分:1)

好像你正在使用不正确的字符集。 您是否尝试过更改此行:

BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf8"),8);

BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));

答案 1 :(得分:1)

变化:

new BufferedReader(new InputStreamReader(is,"utf8"),8)

到:

new BufferedReader(new InputStreamReader(is, "UTF-8"))

的参考文献:

请参阅其他问题:How to parse a JSON Input stream

public InputStreamReader(InputStream in, CharsetDecoder dec)的官方文档为here

UTF-8 字符集信息也位于here