2
我真的需要一個例子如何翻譯文本與谷歌翻譯API V2。j2me谷歌翻譯API
我已經實現已經執行以下操作:
String googleUrl="https://www.googleapis.com/language/translate/v2?key=<My Key>";
googleUrl+="&q=";
googleUrl+=urlEncode(txtFeedback.getString());
googleUrl+="&source=";
googleUrl+=System.getProperty("microedition.locale").substring(0, 2);
googleUrl+="&target=en";
HttpConnection googlAPI = null;
DataInputStream dis = null;
StringBuffer response = new StringBuffer();
googlAPI = (HttpConnection)Connector.open(googleUrl);
googlAPI.setRequestMethod(HttpConnection.GET);
dis = new DataInputStream(googlAPI.openInputStream());
int ch;
while ((ch = dis.read()) != -1) {
response.append((char) ch);
}
String tt = response.toString();
tt = tt.substring(tt.indexOf("{"));
JSONObject js = new JSONObject(tt);
params +=js.getJSONObject("data").getJSONArray("translations").getJSONObject(0)
.getString("translatedText") + crlf;
但是這個代碼拋出證書例外:證書是由一個無法識別的實體
它拋出異常我真正的設備印發三星GT-S5230以及模擬器
真的需要幫助。
如果我做錯了什麼,將會很好地得到一個如何從j2me midlet中調用谷歌翻譯API的例子。
嗨Opeyemi,感謝您的建議,但它沒有幫助。 – okarpov 2012-05-31 18:37:09