json 如何检查响应体值?

gfttwv5a  于 2023-08-08  发布在  其他
关注(0)|答案(1)|浏览(124)

嗨,我想检查JSON响应ID与用户登录ID存储在共享首选项这里是我的JSON响应

{"code":1,"message":"Success","result":[{"id":"1","name":"Albert Einstein","description":"Albert Einstein was a German-born theoretical physicist.","galaxy":"Cartwheel","star":"0008","dob":"1905-05-13","died":"1973-04-06"}]}

字符串
这里是我检查响应体是否为空的地方

retrievedData.enqueue(new Callback<ResponseModel>() {
            @Override
            public void onResponse(Call<ResponseModel> call, Response<ResponseModel>
                    response) {
                if(response == null || response.body() == null){
                    showInfoDialog(ScientistsActivity.this,"ERROR","Response or Response Body is null. \n Recheck Your PHP code.");
                    return;
                }
                if(response == null || response.body() == null){
                    showInfoDialog(ScientistsActivity.this,"ERROR","Response or Response Body is null. \n Recheck Your PHP code.");
                    return;
                }
                List<Scientist> currentPageScientists = response.body().getResult();

                if (currentPageScientists != null && currentPageScientists.size() > 0) {
                    if (action.equalsIgnoreCase("GET_PAGINATED_SEARCH")) {
                        allPagesScientists.clear();
                    }
                    allPagesScientists.addAll(currentPageScientists);
                    // show(ScientistsActivity.this,currentPageScientists.size()+" Scientists Found");
                } else {
                    if (action.equalsIgnoreCase("GET_PAGINATED_SEARCH")) {
                        allPagesScientists.clear();
                    }
                    show(ScientistsActivity.this,"Hey! Reached End. No more Found");
                }
                mAdapter.notifyDataSetChanged();
                hideProgressBar(mProgressBar);
            }


我不知道该怎么做

mpgws1up

mpgws1up1#

我认为你可以使用拦截器与 Spring Boot 。您可以使用postHandle方法检查所有响应。
你可以访问这个页面https://www.tutorialspoint.com/spring_boot/spring_boot_interceptor.htm

相关问题