Whenever I parse JSON string and display the output of json output in android Logcat, I always found
"f������a������m������i������l������y������.������p������n������g"
in Logcat. The actual string is "family.png" but it displays as above. Any idea how to solve this issue?
Here is JSON data.
{"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"}
]}
and generated JSON format is by Coldfusion.
{"members": [
<cfoutput query="getQry">
{"user":"#tuser#", "username":"#tusername#", "avatar":"#tpicture#"} <cfif currentrow LT getTrackQry.recordcount>,</cfif>
</cfoutput>
]}
Here is parse JSON object from URL.
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;
}