|
@@ -29,7 +29,7 @@ public class Translation {
|
|
|
*/
|
|
|
@RequestMapping("translation")
|
|
|
@ResponseBody
|
|
|
- public JSONObject translation(String translationVal, String from, String to, HttpServletRequest request){
|
|
|
+ public String translation(String translationVal, String from, String to, HttpServletRequest request){
|
|
|
// 请求url
|
|
|
String url = "https://aip.baidubce.com/rpc/2.0/mt/texttrans/v1";
|
|
|
Map<String, Object> mapVal = new HashMap<>();
|
|
@@ -47,10 +47,9 @@ public class Translation {
|
|
|
String accessToken = accessToken();
|
|
|
String result = HttpUtil.post(url, accessToken, "application/json", param);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
-// JSONObject jsonObject1 = (JSONObject) jsonObject.get("result");
|
|
|
- System.out.println(jsonObject);
|
|
|
-// List<Map<Object, Object>> list = (List<Map<Object, Object>>) jsonObject1.get("trans_result");
|
|
|
- return jsonObject;
|
|
|
+ JSONObject jsonObject1 = (JSONObject) jsonObject.get("result");
|
|
|
+ List<Map<Object, Object>> list = (List<Map<Object, Object>>) jsonObject1.get("trans_result");
|
|
|
+ return (String) list.get(0).get("dst");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|