How to convert the JSON array to List to create DataControl in oracle MCS?

浪子不回头ぞ 提交于 2019-12-08 09:52:47

问题


Iam trying to create a List View for the below Json code

{"ImageList" :[

 {
  "ENO":"87",
  "ENAME" : "john",
   "EJOB":"clerk",
  },{
    "ENO":"21",
    "ENAME" : "Abdul",
    "EJOB":"Manager",
  } ]
}

This the DataControl Program This DataControl is invoked by another Class

 Runnable mcsJob = new Runnable(){
   public void run(){ 
   try {

           CustomAPI customApi = mobileBackend.getServiceProxyCustomApi();            
           MCSRequest request = new MCSRequest(mobileBackend.getMbeConfiguration());
           request.setConnectionName(mafConnection);            
           request.setRequestURI(requestURI);            
           request.setHttpMethod(httpMethod);            
           request.setPayload(payload==null?"":payload);
           request.setRetryLimit(0);
           HashMap<String,String> headers = new HashMap<String,String>();

           if(httpHeaders!=null)
           {
               headers.putAll(httpHeaders);
           }

           request.setHttpHeaders(headers);  
           MCSResponse response = customApi.sendForStringResponse(request);
           String jsonResponse = (String) response.getMessage(); 
           setEmployeeSearchResponse(jsonResponse);
           //Converting JSON string
           apiResponse.setEmpsearchResponse(employeeSearchResponse);
           JSONObject jsonObject = new JSONObject(apiResponse.getEmpsearchResponse());
           JSONObject bodyObject = jsonObject.getJSONObject("Body");
           JSONObject ProcessObject=bodyObject.getJSONObject("processResponse");
            JSONArray empObject=ProcessObject.getJSONArray("ImageList"); 

           for(int i=0;i<empObject.length();i++)

               {

                JSONObject js = empObject.getJSONObject(i); 
                String name= ""+js.getString("ENO");
                String photo = ""+js.getString("ENAME");
                String empno=""+js.getString("EJOB");
                 EmployeeSearchPOJO  empo=new EmployeeSearchPOJO();
                  empo.setEMPNO(empno);
                   empo.setENAME(name);
                   empo.setPHOTO(photo);   
                   employeeList.add(empo);

               }

      }     

Then I will return the List

I have created EmployeeSearchPOJO class

List I have created is

List<EmployeeSearchPOJO> employeeList=new ArrayList<EmployeeSearchPOJO>();

public void setEmployeeList(List<EmployeeSearchPOJO> employeeList) {
    this.employeeList = employeeList;
}

public List<EmployeeSearchPOJO> getEmployeeList() {
    return employeeList;
}

回答1:


Step1

create a table with columns as ENO,ENAME,EJOB.

Step2

Create a POJO Class with response variables. Generate get and set methods.

Step 3

Parse the json response and store it in to database.(This will increate the performance)

Step4

Create a class which is to be acts as datacontroll and create an arraylist of the type of pojo class. Generate get and set methods for the arraylist. In set method use providerChangeSupport . Write a method return which will fetch the values from the database and store the result (returnType is list) in to the setter method of the arraylist. Call the method from the constructor of the dc class.

Step5

Finally right click on the class and select CreateDataControll. Thenn from the application window of jdeveloper you can see the list in the Data Controlls panel.




回答2:


This is how I did it using GSON.

Gson gson = new Gson();
String json = myJsonString;
Type type = new TypeToken<ArrayList<MyClass>>(){}.getType();
myList= gson.fromJson(json, type);



回答3:


Since your JSONArray contains JSONObject with three attributes,you can create a java class with the exact same member variables i.e. for example

class Employee
{
    String ENO;
    String ENAME:
    String EJOB;

    //create getters ans setters
}

Then within your current code,add the following import:

import oracle.adfmf.framework.api.JSONBeanSerializationHelper;

and in the last loop you can write:

 Employee emp=(Employee) JSONBeanSerializationHelper.fromJSON(Employee .class,js);
employeeList.add(emp);

Now you can set employeeList in EmployeeSearchPOJO class and then use it to create the Data Control.



来源:https://stackoverflow.com/questions/36767439/how-to-convert-the-json-array-to-list-to-create-datacontrol-in-oracle-mcs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!