我是android平臺的新手。我使用下面的代碼從谷歌地址,但我得到奇怪的字符。我很確定它將utf-8字符集設置爲代碼,但我不知道如何。我讀了類似的主題,提出:在http-get嘗試中設置utf-8字符集
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
但下面的代碼就像魅力。任何想法如何把charcet utf-8;對不起,這個基本的問題,並提前感謝。
HttpGet httpGet = new HttpGet(
"http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+ "&sensor=true");
HttpClient client = new DefaultHttpClient();
HttpResponse response;
StringBuilder stringBuilder = new StringBuilder();
try {
response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
int b;
while ((b = stream.read()) != -1) {
stringBuilder.append((char) b);
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
try {
jsonObject = new JSONObject(stringBuilder.toString());
} catch (JSONException e) {
e.printStackTrace();
}
try {
location = jsonObject.getJSONArray("results").getJSONObject(0);
location_string = location.getString("formatted_address");
Log.d("test", "formattted address:" + location_string);
} catch (JSONException e1) {
e1.printStackTrace();
}
你能解釋你的問題是什麼,你需要什麼? –