JAVA怎么取JSON数组里的值?

[{"attributes":{"HIGH_WAY_NO":"G15"},"geometry":{"y":27.4190074740001,"x":120.249168693}},{"attributes":{"HIGH_WAY_NO":"G15"},"geometry":{"y":27.4198835820001,"x":120.24935031}}]
是这样的JSON 数组 我想取X 与Y的值 用JAVA取 怎么取???

PIPIONE
浏览 2383回答 1
1回答

大话西游666

需要写一个方法,把json数据转换成list集合数据public static List&nbsp;jsonToBean(String data, Object bean) {List list = new ArrayList();try {JSONArray array;try {array = new JSONArray(data);for (int i = 0; i < array.length(); i++) {Object toBean = getBean(bean);JSONObject ob = new JSONObject();ob = (JSONObject) array.get(i);toBean = jsonStrToBean(ob, toBean);list.add(toBean);}return list;} catch (JSONException e) {try {Object obj = null;JSONObject jsonObj = new JSONObject(data);Object toBean = getBean(bean);toBean = jsonStrToBean(jsonObj, toBean);list.add(toBean);return list;} catch (JSONException e1) {log.error("Error covert String to JSONObject", e);e1.printStackTrace();}e.printStackTrace();log.error("Error covert String to JSONArray", e);}} catch (SecurityException e) {e.printStackTrace();}return list;}然后取出list集合数据中的值应该没问题了吧。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java