public String fanyiApi(String query) throws JSONException { String httpUrl = "http://apis.baidu.com/apistore/tranlateservice/translate"; String httpArg = "query=" + query + "&from=auto&to=auto"; System.out.println("yzj httpArg = " + httpArg); String jsonResult = TuringUtils.requestApi(httpUrl, httpArg); System.out.println("yzj " + jsonResult); // 网络不好的情况下 todo 处理一下 if (jsonResult == null) { return getResources().getString(R.string.bad_network); } JSONObject obj = new JSONObject(jsonResult.toString()); JSONObject obj2 = (JSONObject) obj.getJSONObject("retData").getJSONArray("trans_result").get(0); return obj2.getString("dst"); }
public String turingApi(String key) throws JSONException { String httpUrl = "http://apis.baidu.com/turing/turing/turing"; // String httpArg = "key=879a6cb3afb84dbf4fc84a1df2ab7319&info=" + key String httpArg = "key=23d4c8cecf65a0c7258078a88743b374&info=" + key + "&userid=132632"; String jsonResult = TuringUtils.requestApi(httpUrl, httpArg); System.out.println("yzj " + jsonResult); if (jsonResult == null) { return getResources().getString(R.string.bad_network); } System.out.println("yzj jsonResult = " + jsonResult); JSONObject obj = new JSONObject(jsonResult.toString()); System.out.println("yzj text = " + obj.getString("text")); return obj.getString("text"); }
public String wordApi(String query) throws JSONException { String httpUrl = "http://opendata.baidu.com/api.php"; String httpArg = "resource_id=4043&query=" + query + "开头的成语"; httpArg = TuringUtils.toUtf8String(httpArg); String jsonResult = TuringUtils.requestApi(httpUrl, httpArg); // 网络不好的情况下 todo 处理一下 if (jsonResult == null) { return getResources().getString(R.string.bad_network); } // JSONObject obj = new JSONObject(jsonResult.toString()); // JSONObject obj2 = (JSONObject) obj.getJSONObject("retData") // .getJSONArray("trans_result").get(0); System.out.println("yzj " + jsonResult); return jsonResult; }