0
开发的应用程式,以不同的话翻译成不同的语言 使用Yandex的转换器获得的浏览器的正确的结果
转换吻
结果JSON对象是 {"code":200,"lang":"en-hi","text":["चुम्बन"]} //proper
但同时获得导致在应用 结果 {"code":200,"lang":"en-hi","text":["à¤à¥à¤®à¥à¤¬à¤¨"]}
的Android无法识别不同的语言字体
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
}
}
有什么办法,我可以得到正确的结果?
请帮助
问候
也许你是一个错误的文本编码工作?函数getJSONFromUrl看起来像什么? – Chris623
在问题中加入 – phpdroid
请您提供服务器端代码。我认为这是关于编码。在PHP(例如)你应该使用这样的[链接](http://stackoverflow.com/questions/16498286/why-does-the-php-json-encode-function-convert-utf-8-strings-到十六进制entit)。 –