zoukankan      html  css  js  c++  java
  • 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);/*请求数据*/ }
  • 相关阅读:
    csu 1141 节能
    WA:ZOJ 1025 Wooden Sticks
    UVa 531 Compromise
    UVa 437 The Tower of Babylon
    UVa 10285 Longest Run on a Snowboard
    在asp.net使用web.config身份验证
    掌握 Ajax,第 6 部分: 建立基于 DOM 的 Web 应用程序
    面向对象编程思想
    一步一步学Remoting之五:异步操作
    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
  • 原文地址:https://www.cnblogs.com/dingxiansen/p/7520622.html
Copyright © 2011-2022 走看看