後端java解析複雜巢狀json
阿新 • • 發佈:2019-01-24
其實不是很複雜
百度翻譯傳過來的json資料:{"from":"zh","to":"en","trans_result":[{"src":"高度600米","dst":"Height 600 meters"}]}
現在要取出dst對應的值:Height 600 meters
String date="{"from":"zh","to":"en","trans_result":[{"src":"高度600米","dst":"Height 600 meters"}]}"; JSONObject ob=JSONObject.fromObject(date); JSONArray trans_result=(JSONArray) ob.get("trans_result"); JSONObject trans_result_content=(JSONObject) trans_result.get(0);
輸出
System.out.println(ob);
System.out.println( ob.get("trans_result"));
System.out.println(trans_result_content);
System.out.println(trans_result_content.get("dst"));
結果