从服务器获取阵列

时间:2019-01-11 12:35:46

标签: java android listview android-volley

我想通过服务器获取信息并添加到listView, 但是我没有解决它的好方法。 但是我写了一个 Model.class 来从服务器获取数组,但是它不起作用。

我的代码如下: 该代码放在 ListViwe 部分

    // volley part codes ----------------------------------------------------------------------------------------------------------------------------------------
    public void registration_user_web ( final String url) throws JSONException {


        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {




                    @Override
                    public void onResponse(String response) {

                        Toast.makeText(getApplicationContext(),response.toString(),Toast.LENGTH_LONG).show();

                        ListInfoModel  info_list = new ListInfoModel();
                        Gson gson = new Gson();

                        info_list.info_gason_parss = gson.fromJson(response,ListInfoModel.class);
                        info_list.info_gason_parss.result.get(2);
                        String a = info_list.info_gason_parss.toString();
                        Toast.makeText(getApplicationContext(),a.toString(),Toast.LENGTH_LONG).show();

                        //  Toast.makeText(getApplicationContext(),response.toString(),Toast.LENGTH_LONG).show();

                    }

                },

                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        //  Toast.makeText(getApplicationContext(),response.toString(),Toast.LENGTH_LONG).show();
                    }
                }) {

            @Override
            protected java.util.Map<String, String> getParams() {
                java.util.Map<String, String> params = new HashMap<String, String>();
//                params.put("image" , imageData);
                return params;
            }

        };


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

模型类:

public class ListInfoModel {

    public static ListInfoModel info_gason_parss;

    // parse jason
    public ArrayList<get_farex_list> result ;

    public class get_farex_list {
        public String id;
        public String symbol;
        public String stars;
        public String monetary;
    }
}

json代码为: enter image description here

0 个答案:

没有答案