博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Request JSON
阅读量:5999 次
发布时间:2019-06-20

本文共 1439 字,大约阅读时间需要 4 分钟。

https://developer.android.com/training/volley/request.html

Request JSON

Volley provides the following classes for JSON requests:

JsonArrayRequest—A request for retrieving a JSONArray response body at a given URL.

JsonObjectRequest—A request for retrieving a JSONObject response body at a given URL, allowing for an optional JSONObject to be passed in as part of the request body.
Both classes are based on the common base class JsonRequest. You use them following the same basic pattern you use for other types of requests. For example, this snippet fetches a JSON feed and displays it as text in the UI:

TextView mTxtDisplay;ImageView mImageView;mTxtDisplay = (TextView) findViewById(R.id.txtDisplay);String url = "http://my-json-feed";JsonObjectRequest jsObjRequest = new JsonObjectRequest        (Request.Method.GET, url, null, new Response.Listener
() { @Override public void onResponse(JSONObject response) { mTxtDisplay.setText("Response: " + response.toString()); }}, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub }});// Access the RequestQueue through your singleton class.MySingleton.getInstance(this).addToRequestQueue(jsObjRequest);

For an example of implementing a custom JSON request based on Gson, see the next lesson, Implementing a Custom Request.

转载于:https://www.cnblogs.com/xiangnan/p/5513542.html

你可能感兴趣的文章
Electron Cash钱包存BCH教程
查看>>
自定义key解决zabbix端口监听取值不准确的问题
查看>>
入门级----黑盒测试、白盒测试、手工测试、自动化测试、探索性测试、单元测试、性能测试、数据库性能、压力测试、安全性测试、SQL注入、缓冲区溢出、环境测试...
查看>>
composer 安装 ubuntu 12.04
查看>>
微服务(二)hystrix
查看>>
Performing a thread dump in Linux or Windows--reference
查看>>
推荐系统中常用算法 以及优点缺点对比
查看>>
cocos2d-x v3.2环境配置(现在3.x版本号可以配置该)
查看>>
穷举法解决旅行商问题
查看>>
括号配对问题
查看>>
Oracle自学笔记(一)
查看>>
利用5w1h写出高效的git commit
查看>>
用div和css样式控制页面布局
查看>>
Python自定义库文件路径
查看>>
Get和Post的区别
查看>>
Redis--优化
查看>>
JSTL截取字符串以及格式化时间
查看>>
Bugtags 使用技巧之 setUserData
查看>>
Go语言标准库之JSON编解码
查看>>
使用windows search 搜索文件和文件夹(一)
查看>>