Android 无法识别不同的语言字体
Android not able to recognize different language Fonts
制作了一个应用程序将不同的单词翻译成不同的语言
使用 Yandex 转换器在浏览器上获得正确的结果
转换 Kiss
JSON 对象的结果是
{"code":200,"lang":"en-hi","text":["चुम्बन"]} //proper
但是在应用程序上获得结果时
结果
{"code":200,"lang":"en-hi","text":["à¤à¥à¤®à¥à¤¬à¤¨"]}
JSONParser jParser = new JSONParser();
// get json string from url
JSONObject json = jParser.getJSONFromUrl(yourJsonStringUrl);
geJSONFromUrl 函数
public JSONObject getJSONFromUrl(String urlSource) {
//make HTTP request
try {
URL url = new URL(urlSource);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
inputStream = new BufferedInputStream(urlConnection.getInputStream());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//Read JSON data from inputStream
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
inputStream.close();
json = sb.toString();
} catch (Exception e) {
Log.e(TAG, "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e(TAG, "Error parsing data " + e.toString());
}
return jObj;// return JSON String
}
}
有什么方法可以得到正确的结果吗?
请帮助
问候
已更改
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);
至
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
制作了一个应用程序将不同的单词翻译成不同的语言
使用 Yandex 转换器在浏览器上获得正确的结果
转换 Kiss
JSON 对象的结果是
{"code":200,"lang":"en-hi","text":["चुम्बन"]} //proper
但是在应用程序上获得结果时
结果
{"code":200,"lang":"en-hi","text":["à¤à¥à¤®à¥à¤¬à¤¨"]}
JSONParser jParser = new JSONParser();
// get json string from url
JSONObject json = jParser.getJSONFromUrl(yourJsonStringUrl);
geJSONFromUrl 函数
public JSONObject getJSONFromUrl(String urlSource) {
//make HTTP request
try {
URL url = new URL(urlSource);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
inputStream = new BufferedInputStream(urlConnection.getInputStream());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//Read JSON data from inputStream
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
inputStream.close();
json = sb.toString();
} catch (Exception e) {
Log.e(TAG, "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e(TAG, "Error parsing data " + e.toString());
}
return jObj;// return JSON String
}
}
有什么方法可以得到正确的结果吗?
请帮助
问候
已更改
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);
至
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);