其它数据类型和Json的转化
生活随笔
收集整理的這篇文章主要介紹了
其它数据类型和Json的转化
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.ResultSet→Json
public static String resultSetToJson(ResultSet rs) throws SQLException,JSONException { // json數(shù)組 JSONArray array = new JSONArray(); // 獲取列數(shù) ResultSetMetaData metaData = rs.getMetaData(); int columnCount = metaData.getColumnCount(); // 遍歷ResultSet中的每條數(shù)據(jù) while (rs.next()) { JSONObject jsonObj = new JSONObject(); // 遍歷每一列 for (int i = 1; i <= columnCount; i++) { String columnName =metaData.getColumnLabel(i); String value = rs.getString(columnName); jsonObj.put(columnName, value); } array.put(jsonObj); } return array.toString(); }?
轉(zhuǎn)載于:https://www.cnblogs.com/123-4/p/3800917.html
總結(jié)
以上是生活随笔為你收集整理的其它数据类型和Json的转化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NXP (I.MX6ULL) GPT高精
- 下一篇: 树链剖分解析---WYD