My question is that i have to display my data which is fetched from JSON file ,the json file is below. But i want the data to be in sorted form after getting from JSON file i.e after the rest call when data is obtained from controller in viewmodel,so that i can directly display it on the View Class. which has cardviews.
{"employeeList":[ {"employeeName": "aaaa","employeeStatus": "Trainee","company": "IBM","mobile": "894996662" }, {"employeeName": "bbbb","employeeStatus": "Fellowship","company": "Wipro","mobile": "9876000021" }, {"employeeName": "cccc","employeeStatus": "Fellowship","company": "CGI","mobile": "9876000021" }, {"employeeName": "cccc","employeeStatus": "Fellowship","company": "CGI","mobile": "9876000021" } ]}
And the .java file is below,were i have not done the sorting.I need the help,Thank you.
try { //As the data in rest call contained in JSONObject inside that JSONArray and inside //JSONArray JSONObject is there ,Hence to get the data and set to the Model Class //Creating JSON Object and obtained the data in bytes JSONObject jsonObject = new JSONObject(new String(bytes)); Log.i("json object", "employeeList: "); if (jsonObject != null) { JSONArray jsonArray = jsonObject.getJSONArray("employeeList"); Log.i("json Array", "employeeList: "+ jsonArray.length()); //Creating the object of modelClass if (jsonArray.length() != 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject childObject = jsonArray.getJSONObject(i); //Through the object of model Class the obtained data is set to the //Model class EnggFragModel enggFragModel = new EnggFragModel(); enggFragModel.setImageurl(childObject.getString("imageUrl")); Log.i("image", "employeeData: "+childObject.getString("imageUrl")); enggFragModel.setEmployeeName(childObject.getString("employeeName")); enggFragModel.setEmployeeStatus(childObject.getString("employeeStatus")); enggFragModel.setCompany(childObject.getString("company")); enggFragModel.setEmployeeMobile(childObject.getString("mobile")); enggFragModel.setEmployeeEmail(childObject.getString("emailId")); enggFragModel.setEngineerID(childObject.getString("engineerId")); Log.i("EngineerId", "employeeData: "+ childObject.getString("engineerId")); enggArrayList.add(enggFragModel); } enggViewModelInterface.enggViewMInterface(enggArrayList); Log.i("Employee", "employeeList: "+ enggArrayList); } } } catch (JSONException e) { e.printStackTrace(); } Log.i("Employee", "employeeList: ");