2021年3月18日星期四

How to get JSON Structure removing duplicates in using Java after getting Data from DB in Java?

This is what my Input is which is coming from DB , Here the thing is I dont want to duplicate the record may be object_name or object_types as given in response ..can someone guide me how to remove duplicates and put in one tree .

 Object_Name         Object Types   PermissionTypes  General Settings    Multi Currency          VIEW  General Settings    Multi Currency          EDIT  General Settings    Localization            VIEW  General Settings    Localization             EDIT  General Settings    Planning Horizon         VIEW  General Settings    Planning Horizon          EDIT  General Settings    Planning Horizon          CLONE  

And I am expecting output something like this

[    {      "groupName": "General Settings",      "rbacObject": "MultiCurrency",      "permissionType": [        "view",        "edit"      ]    },    {      "groupName": "Data Mappings",      "rbacObject": "Planning Horizon",      "permissionType": [        "edit",        "clone"      ]    }  ]  

And this is what I am trying to code

public static void main(String args[]) throws Exception {        JSONObject jsonObject = new JSONObject();        JSONArray array = new JSONArray();        ResultSet rs = RetrieveData();        while(rs.next()) {           JSONObject record = new JSONObject();           record.put("groupName", rs.getString("OBJECT_TYPE"));           record.put("rbacObject", rs.getString("object_name"));           record.put("permissionType", rs.getString("permission_type"));           array.put(record);        }        jsonObject.put("JSON_OBJECT", array);        try {           System.out.println(jsonObject);        } catch (Exception e) {           e.printStackTrace();        }     }  }  
https://stackoverflow.com/questions/66688087/how-to-get-json-structure-removing-duplicates-in-using-java-after-getting-data-f March 18, 2021 at 05:19PM

没有评论:

发表评论