对于String类型的此类数据:
{"tables":[{"sql":"select * from 6_acc","remark":"","description":"","name":"admin_user_de","sqlId":""}
,{"sql":"select * from 6_acc","remark":"","description":"","name":"admin_tre","sqlId":""}]}
可用如下方法:
Long dpId = Long.parseLong(dpid);
DataPackagePO dp = dataPackageService.getDataPackageById(dpId);
List<Map<String, Object>> tables = new ArrayList<Map<String, Object>>();
try{
JSONObject tablesJson = new JSONObject(dp.getContent());
if(tablesJson!=null&&!tablesJson.toString().trim().equals("")){
org.json.JSONArray tablesArray = tablesJson.getJSONArray("tables");
for(int i=0;i<tablesArray.length();i++){
Map<String, Object> table = new HashMap<String, Object>();
JSONObject tableJson = tablesArray.getJSONObject(i);
table.put("tableName", tableJson.getString("name"));
table.put("remark", tableJson.getString("remark"));
table.put("sql", tableJson.getString("sql"));
table.put("previewData", tableJson.getString("previewData"));
table.put("description", tableJson.getString("description"));
table.put("sqlId", tableJson.getString("sqlId"));
tables.add(table);
}
来读取每一个{}内的对象,返回List<Map<String,Object>>类型