后端java解析复杂嵌套json

其实不是很复杂

百度翻译传过来的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"));

结果


你可能感兴趣的:(小结)