dontoften8899 2016-03-22 20:27
浏览 161

从数据库中获取后,JSON对象不显示值

I am fetching data from database in android and i can see data fetching from databse in JSON format using POSTMAN but when i am trying to display it in my android application, its not displaying any value. Values from POSTMAN:

{
  "result": [
    {
      "Date": "18-3-2016",
      "Events": "Local Holiday"
    },
    {
      "Date": "23-3-2016",
      "Events": "Monthly Fees"
    },
    {
      "Date": "15-4-2016",
      "Events": "Monthly Fees"
    },
    {
      "Date": "23-4-2016",
      "Events": "Annual Day"
    },
    {
      "Date": "30-4-2016",
      "Events": "session end"
    },
    {
      "Date": "9-4-2016",
      "Events": "Parent Teacher Meeting"
    }
  ]
}

I am following some tutorials and Code using:

 private void getData() {


        loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,false);

        String url = config_events.DATA_URL;

        StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                loading.dismiss();
                showJSON(response);
            }
        },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(events.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
                    }
                });

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
    }

    private void showJSON(String response) {

        String date = "";
        String comment="";
        //String vc = "";
        try {
            JSONObject jsonObject = new JSONObject(response);
            JSONArray result = jsonObject.getJSONArray(config_events.JSON_ARRAY);
            JSONObject collegeData = result.getJSONObject(0);
            date = collegeData.getString(config_events.KEY_NAME);
            comment = collegeData.getString(config_events.KEY_ADDRESS);
            //vc = collegeData.getString(config_events.KEY_VC);
        } catch (JSONException e) {
            e.printStackTrace();
        }
textViewResult.setText("Date:"+date + "Comment:"+ comment);
  • 写回答

2条回答 默认 最新

  • dongpaipu8394 2016-03-22 21:19
    关注

    Assuming that you have tried to debug it, this could be the problem of user-permissions in Android manifest. Make sure that you have following permissions in your manifest file.

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)