• android 网络请求Volley的简单使用


    下载到本地jar包或者在线导入,jar地址:链接:http://pan.baidu.com/s/1gf3VZAb 密码:mmye

    //定义变量
    private RequestQueue mQueue=Volley.newRequestQueue(context);
    //具体的请求方法

    /*
    *参数1:请求方式,POST,GET等
    *参数2:请求路径
    */
    StringRequest stringRequest = new StringRequest(Request.Method.POST, NetWorkUrl.getrecord, new Response.Listener<String>() {
           /*请求成功之后返回的json字符串,这里的字符串没有进行加密,所以直接绑定对象*/ @Override
    public void onResponse(String s) { UserEntity userEntity = new UserEntity(); Log.d("TAG", s.toString()); Log.e("reocrd首页", "首页数据Record----------:" + s.toString()); try { JSONObject jo = new JSONObject(s); /*解析最外层数据*/ String he = jo.getJSONArray("data").toString(); /*直接解析成对象集合*/ List<RecordEntity> entities = JSON.parseArray(he, RecordEntity.class); list.clear(); for (RecordEntity entity : entities) { RecordEntity recordEntity = new RecordEntity( entity.getId(), entity.getUid(), entity.getContent(), entity.getAddress(), entity.getFile(), entity.getFiletype(), entity.getFileduration(), entity.getCategoryid(), entity.getAddtime(), entity.getComments(), entity.getLikes(), entity.getLikenum()); Log.e("e", "---------------tiem00000000:" + entity.getAddtime()); list.add(recordEntity); } // lvList.notifyAll(); adapter = new RecordAdapter(LocationApplication.getContext(), list); lvList.setAdapter(adapter); } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { } }) {
           /*请求需要传递的参数*/ @Override
    protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> map = new HashMap<String, String>(); map.put("id", "1"); return map; } }; mQueue.add(stringRequest);/*请求数据*/ }
  • 相关阅读:
    delphi 属性 参数 新注释
    delphi query阻塞执行 长时间执行sql的解决办法
    FDLocalSQL
    C# Webservice
    vmware的centos 6虚拟机如何共享文件夹?
    tomcat如何配置启动时自动部署webapps下的war包
    tomcat如何配置context的docBase
    windows本地启动tomcat闪退
    jfinal 字节流存储文件以及解、压缩工具类
    java try catch 异常后还会继续执行吗
  • 原文地址:https://www.cnblogs.com/dingxiansen/p/7520622.html
Copyright © 2020-2023  润新知