URLに問題があり、応答としてnullを取得しています。また、エンコードしようとしましたが、応答が期待どおりに得られません..
これが私のコードです:
try
{
String url = "http://mymemory.translated.net/api/get?q=Thanks&langpair=EN|KO" + query;
Log.i("URL", ">>>"+url);
JSONObject Responce = getJSONfromURL(url.toString());
Log.e("", "Responce"+Responce);
}
catch (Exception e) {}
エラーログ:
10-12 20:13:35.411: INFO/URL(6844): >>>http://mymemory.translated.net/api/get?q=Thanks&langpair=EN|KO
10-12 20:13:35.531: ERROR/log_tag(6844): Error in http connection java.lang.IllegalArgumentException: Illegal character in query at index 59: http://mymemory.translated.net/api/get?q=Thanks&langpair=EN|KO
10-12 20:13:35.531: ERROR/log_tag(6844): Error converting result java.lang.NullPointerException
10-12 20:13:35.531: ERROR/log_tag(6844): Error parsing data org.json.JSONException: End of input at character 0 of
10-12 20:13:35.541: ERROR/(6844): Responcenull
エンコード後
URL エンコード方式が適用されます。
String query = URLEncoder.encode("Thanks&langpair=EN|KO", "utf-8");
String url = "http://mymemory.translated.net/api/get?q=" + query;
Log.i("URL", ">>>"+url);
JSONObject Responce = getJSONfromURL(url.toString());
Log.e("", "Responce"+Responce);
ログ::
10-12 20:21:01.180: INFO/URL(7050): >>>http://mymemory.translated.net/api/get?q=Thanks%26langpair%3DEN%7CKO
10-12 20:21:01.710: ERROR/(7050): Responce{"responseData":{"translatedText":"INVALID LANGUAGE PAIR SPECIFIED. EXAMPLE: LANGPAIR=EN|IT USING 2 LETTER ISO OR RFC3066 LIKE ZH-CN. ALMOST ALL LANGUAGES SUPPORTED BUT SOME MAY HAVE NO CONTENT"},"matches":"","responseStatus":403,"responseDetails":"INVALID LANGUAGE PAIR SPECIFIED. EXAMPLE: LANGPAIR=EN|IT USING 2 LETTER ISO OR RFC3066 LIKE ZH-CN. ALMOST ALL LANGUAGES SUPPORTED BUT SOME MAY HAVE NO CONTENT"}