如何在我的 JSON 数据中查找最低记录以及如何在我的 JSON 数据中查找总页记录



这是我的控制器类,我的 pojo 类是 sampledata 。 我想从 JSON 数据中获取"总_page"和较低的"ID"

这是我的客户端 JSON 数据 {"example":1,"page":1,total_page":1,"data":[{"id":1,"f_name:"ss"},{"id":2,"f_name:"sss"}]}

    public class StudentDetailsController {
        public static void main(String[] args) throws SQLException {
            Client client = Client.create();
            WebResource webResource = client
                    .resource("http://somethinghere");
            ClientResponse response = webResource.accept("application/json").get(
                    ClientResponse.class);
    if (response.hasEntity()) {
                try {
                    String message = String.valueOf(response
                            .getEntity(String.class));
                    System.out.println(message);
                    Gson gson = new Gson();
                    System.out.println("the list -s "+gson);
                    List<sampledata> list = gson.fromJson(message,
                            new TypeToken<List<sampledata>>() {
                            }.getType());
    for (StudentDetails c : list) {
                        System.out.println("list size::::::::"  + list.size());
                        System.out.println(c.id());
                        System.out.println(c.getf_name());                  
    }
    }

一旦您使用库(例如 Gson)反序列化 Json,您只需通过 getter 方法访问属性即可。

 for (StudentDetails c : list) {
     c.getTotalPage();
     c.getData().get(0).getId()
 }

最新更新