我有一个从数据库(JSON MySQL 中的数据存储)中检索数据的程序。
public static int selectData(Connection conn, String db_type) throws SQLException {
JSONObject obj = new JSONObject();
String q = "SELECT * FROM common_attr_test";
PreparedStatement preparedStatement = conn.prepareStatement(q);
preparedStatement.execute();
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
String uuid_user = rs.getString("uuid");
String attributes_uuid = rs.getString("attributes");
obj.put("uuid", uuid_user);
obj.put("attributes", attributes_uuid);
}
System.out.println("JSON Obj: "+obj);
return 1;
} // end selectData function
我设法得到了对象。输出是:
JSON对象:
{
"attributes": "{\"1\": {\"1\": 2, \"2\": 2, \"3\": 3}, \"2\": {\"h4y4/1123\": 4, \"h4yp:/4/1123\": 1, \"h4yyp:/4/1123\": 1, \"httyyyyp:/4/1123\": 1}, \"3\": {\"Chrome|Windows NT 6.1\": 7}, \"7\": {\"2\": 4, \"6\": 1}, \"8\": {\"1\": 1, \"2\": 1, \"3\": 1, \"4\": 1, \"5\": 1, \"6\": 1, \"7\": 1}}",
"uuid": "izyani1234561"
}
我需要关于如何处理数据并将信息放入不同数组/对象的建议。例如
array1 - 1:{1:2, 2:2, 3:3}
array2 - 7:{2:4, 6:1}
array3 - 8:{1:1, 2:1, 3:1, 4:1, 5:1, 6:1, 7:1}
谢谢你。
泛舟湖上清波郎朗
相关分类