Android Java UTF-8 HttpClient Problème

Je suis bizarre personnage problèmes d'encodage avec un tableau JSON qui est extrait d'une page web. Le serveur est de l'envoi de retour cet en-tête:

Content-Type text/javascript; charset=UTF-8

Aussi je peux regarder la sortie JSON dans Firefox ou tout autre navigateur et Unicode, les caractères s'affichent correctement. La réponse contient parfois des mots d'une autre langue avec des accents de symboles et de ces. Cependant, je suis l'obtention de ces étranges marques de question quand je le tire vers le bas et de le mettre à une chaîne de caractères en Java. Voici mon code:

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 = entity.getContent();
String jsonText = convertStreamToString(instream);
Toast.makeText(getApplicationContext(), "Response: "+jsonText, Toast.LENGTH_LONG).show();
}
}
} catch (MalformedURLException e) {
Toast.makeText(getApplicationContext(), "ERROR: Malformed URL - "+e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "ERROR: IO Exception - "+e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "ERROR: JSON - "+e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
private static String convertStreamToString(InputStream is) {
/*
* To convert the InputStream to String we use the BufferedReader.readLine()
* method. We iterate until the BufferedReader return null which means
* there's no more data to read. Each line will appended to a StringBuilder
* and returned as String.
*/
BufferedReader reader;
try {
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
} catch (UnsupportedEncodingException e1) {
//TODO Auto-generated catch block
e1.printStackTrace();
}
StringBuilder sb = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}

Comme vous pouvez le voir, je suis spécifiant l'UTF-8 sur le InputStreamReader mais chaque fois que je vois le retour JSON texte par le Toast qu'il a d'étranges points d'interrogation. Je pense que j'ai besoin d'envoyer l'InputStream à un byte[] à la place?

Merci d'avance pour toute aide.

OriginalL'auteur Michael Taggart | 2010-12-18