后端java解析复杂嵌套json

来源:互联网 发布:淘宝视频服务无法订购 编辑:程序博客网 时间:2024/06/07 03:02

其实不是很复杂

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

结果


原创粉丝点击