android 网络请求Volley的简单使用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android 网络请求Volley的简单使用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1748字,纯文字阅读大概需要3分钟。
内容图文
![android 网络请求Volley的简单使用](/upload/InfoBanner/zyjiaocheng/1296/67acae4442f349cead7e305c2b7c8ba9.jpg)
下载到本地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 publicvoid 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 publicvoid 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);/*请求数据*/ }
原文:http://www.cnblogs.com/dingxiansen/p/7520622.html
内容总结
以上是互联网集市为您收集整理的android 网络请求Volley的简单使用全部内容,希望文章能够帮你解决android 网络请求Volley的简单使用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】