java中JSONArray、JSONObject、List、String之间的转换「建议收藏」 您所在的位置:网站首页 JSONArray转JSONObject java中JSONArray、JSONObject、List、String之间的转换「建议收藏」

java中JSONArray、JSONObject、List、String之间的转换「建议收藏」

2024-07-07 20:19| 来源: 网络整理| 查看: 265

大家好,又见面了,我是你们的朋友全栈君。

一、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 实验室设备网 版权所有