【发布时间】:2011-09-04 23:40:22
【问题描述】:
我正在尝试在我的应用引擎项目中使用 Google Translate v2 api。然而,对于重音字符,它的编码是混乱的[例如“学生”这个词,在法语中应该是“étudiants”,变成了“étudiants”]。这是我的代码。
URL url = new URL(
"https://www.googleapis.com/language/translate/v2?key=" + KEY
+ "&q=" + urlEncodedText + "&source=en&target="
+ urlEncodedLang);
try {
InputStream googleStream = url.openStream();
// make a new bufferred reader, by reading the page at the URL given
// above
BufferedReader reader = new BufferedReader(new InputStreamReader(
googleStream));
// temp string that holds text line by line
String line;
// read the contents of the reader/the page by line, until there are
// no lines left
while ((line = reader.readLine()) != null) {
// keep adding each line to totalText
totalText = totalText + line + "\n";
}
// remember to always close the reader
reader.close();
} catch (Exception ex) {
ex.printStackTrace();
}
在浏览器(Ubuntu 上的 Chrome)中输入相同的 URL 可以正常工作,并返回包含正确重音字符的 JSON 响应。
我在这里缺少什么? 谢谢
【问题讨论】:
标签: java google-app-engine encoding google-translate