This page shows how to consume a JSON (GET and POST)
How to consume a JSON and populates the data in a table
Using the method: Core.httpGet (String url, String [] mediaType, Class result) ... the script makes a Http Get request and returns a JSON as a String, then it reads the returned JSON and populates the data in the table shown in the figure below
publicResponseactionIndex() throws IOException, IllegalArgumentException, IllegalAccessException{Resttest model =newResttest();model.load();ResttestView view =newResttestView();String json =Core.httpGet("https://jsonplaceholder.typicode.com/posts",newString[] {},String.class);model.setTable_1(newArrayList<Resttest.Table_1>());JSONArray aux1 =newJSONArray(json);for(int i =0; i <aux1.length(); i ++) {JSONObject obj =aux1.getJSONObject(i);Resttest.Table_1 row =new Resttest.Table_1();row.setQuote(obj.getString("body"));row.setSequence(""+obj.getInt("id"));row.setTitulo(obj.getString("title"));row.setUserid(""+obj.getInt("userId"));model.getTable_1().add(row);}/*----#end-code----*/view.setModel(model);returnthis.renderView(view);}
How to consume a JSON/POST
The script below allows you to collect the data (Name, Job) of the form shown in the fig. 2 and then make an HTTP POST, invoking an API ... If the operation is successful, it returns the JSON as a String and prints it in a message INFO.