java中JSONArray、JSONObject、List、String之间的转换「建议收藏」 | 您所在的位置:网站首页 › JSONArray转JSONObject › java中JSONArray、JSONObject、List、String之间的转换「建议收藏」 |
大家好,又见面了,我是你们的朋友全栈君。 一、JASSONArray转为JSONObject JSONArray result_type = new JSONArray(); StringBuffer cdsIdxType = new StringBuffer(); cdsIdxType.append(” select id from table_type “); result_type = jdbcTemp.queryForJSONArray(cdsIdxType.toString()); JSONObject jsonObject = (JSONObject) result_type.get(i); 二、JASONArray转为List JSONArray result_type = new JSONArray(); StringBuffer cdsIdxType = new StringBuffer(); cdsIdxType.append(” select id from table_type “); result_type = jdbcTemp.queryForJSONArray(cdsIdxType.toString()); ArrayList list_type = new ArrayList(); for (int i = 0; i < result_type.size(); i++) { JSONObject jsonObject = (JSONObject) result_type.get(i); list_type.add(jsonObject.get(“id”)); } 三、JSONArray转为String JSONArray result_type = new JSONArray(); StringBuffer cdsIdxType = new StringBuffer(); cdsIdxType.append(” select id from table_type “); result_type = jdbcTemp.queryForJSONArray(cdsIdxType.toString()); String typeAll = “”; ArrayList list_type = new ArrayList(); for (int i = 0; i < result_type.size(); i++) { JSONObject jsonObject = (JSONObject) result_type.get(i); list_type.add(jsonObject.get(“id”)); } for(int j=0;j |
CopyRight 2018-2019 实验室设备网 版权所有 |