android 網路請求Volley的簡單使用

來源:互聯網
上載者:User

標籤:tar   return   簡單   volley   trace   request   address   ica   tco   

下載到本地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);/*請求資料*/ }

 

android 網路請求Volley的簡單使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.