首页 > 解决方案 > Gson 未使用 gson.getJson 填充列表

问题描述

我将数据转换为 JSON 并接收它。但是缺少一些东西。我不知道是什么。我有 2 个链接,其中 1 个有效。它正在接收响应并将数据转换为 JSON。

我试过: 我用新数据库替换旧数据库,但它不起作用。旧数据库再次运行。我检查了表格和列,但两者都是相同的。还有什么我应该尝试的。请帮忙!

 private void requestData(String uri) {
    JsonObjectRequest request = new JsonObjectRequest(uri,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Utils.psLog("Response > " + response);
                    try {
                        String status = response.getString("status");
                        if (status.equals(jsonStatusSuccessString)) {
                            progressWheel.setVisibility(View.GONE);
                            Gson gson = new Gson();
                            Type listType = new TypeToken<List<PShopData>>() {
                            }.getType();

                            pShopDataList = gson.fromJson(response.getString("data"), listType);
                            if(pShopDataList != null ) {
                                Utils.psLog("Shop Count : "  + pShopDataList.size());
                                if (pShopDataList.size() > 1) {
                                    singleLayout.setVisibility(View.GONE);
                                    mRecyclerView.setVisibility(View.VISIBLE);
                                    updateDisplay();
                                } else {
                                    mRecyclerView.setVisibility(View.GONE);
                                    singleLayout.setVisibility(View.VISIBLE);
                                    stopLoading();
                                    updateSingleDisplay();
                                }
                                updateGlobalCityList();
                            }
                        } else {
                            stopLoading();
                            Utils.psLog("Error in loading ShopList.");
                        }
                    } catch (JSONException e) {
                        Utils.psErrorLogE("Error in loading ShopList.", e);
                        stopLoading();
                        e.printStackTrace();
                    } catch (Exception e){
                        Utils.psErrorLog("Error in loading", e.getMessage());
                    }
                }
            },

            new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError ex) {
                    progressWheel.setVisibility(View.GONE);
                    stopLoading();
                    try {
                        display_message.setVisibility(View.VISIBLE);
                        display_message.setText(connectionError);
                    }catch (Exception e){
                        Utils.psErrorLogE("Error in Connection Url.", e);
                    }
                }
            });

    request.setRetryPolicy(new DefaultRetryPolicy(
            5000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    request.setShouldCache(false);
    VolleySingleton.getInstance(getActivity()).addToRequestQueue(request);
}

我试过调试代码。这是屏幕截图。 在此处输入图像描述

这是Logcat:

07-05 21:20:38.130 20632-20644/com.logictex.usamapharmacy I/zygote:后台并发复制 GC 释放 444(367KB) AllocSpace 对象,0(0B) LOS 对象,49% 空闲,1872KB/3MB,暂停 7.903 ms 总计 450.981ms 07-05 21:20:38.294 20632-20638/com.logictex.usamapharmacy I/zygote:做完整的代码缓存收集,代码=91KB,数据=56KB 07-05 21:20:38.296 20632-20638/ com.logictex.usamapharmacy I/zygote:代码缓存收集后,code=91KB,data=45KB 07-05 21:20:38.557 20632-20632/com.logictex.usamapharmacy I/Choreographer:跳过了 99 帧!应用程序可能在其主线程上做了太多工作。07-05 21:20:38.621 20632-20673/com.logictex.usamapharmacy D/EGL_emulation: eglMakeCurrent: 0xa5b3ffa0: ver 2 0 (tinfo 0xa5becec0) 07-05 21:20:38.627 20632-20812/com.logictex.usamapharmacy E /StudioProfiler:JVMTI 错误:392 20632-20632/com.logictex.usamapharmacy D/TEAMPS:线路:323 07-05 21:20:42.398 20632-20632/com.logictex.usamapharmacy D/TEAMPS:类:类 java.lang.String 07-05 21 :20:42.402 20632-20632/com.logictex.usamapharmacy I/Choreographer: 跳过 70 帧!应用程序可能在其主线程上做了太多工作。07-05 21:20:42.812 20632-20666/com.logictex.usamapharmacy V/FA:不活动,与服务断开连接

标签: jsonandroid-studiogsonandroid-volley

解决方案


推荐阅读