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<JSONObject>() { @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.

Request JSON的更多相关文章

  1. robotframework接口测试(一)—Get request json

    (前提:引入了 requests.requestsLibrary等相关库,这样才可以只有相关的关键字.) 理想中的过程: 1. 创建session 2. 在该session下发起请求 3. 验证返回结 ...

  2. kotlin spring mvc request json 请求

    // json 代码{ /*用户信息*/ user: { username: '{$user.username}', headImg: '{$user.headImg}', targetId: '{$ ...

  3. AttributeError: 'Request' object has no attribute 'json', cherrypy 无法接收到json字符串,解决方法

    @cherrypy.expose @cherrypy.tools.accept(media="application/json")   #加入这个装饰器 @cherrypy.too ...

  4. flask request 获取json内容2种方式

    # -*- coding: utf-8 -*-from flask import request, jsonify, json, Moduleimport loggingfrom web.utils. ...

  5. Android JSON 解析库的使用 - Gson 和 fast-json

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族 ...

  6. 第三篇 request篇

    每个框架中都有处理请求的机制(request),但是每个框架的处理方式和机制是不同的 为了了解Flask的request中都有什么东西,首先我们要写一个前后端的交互 基于HTML + Flask 写一 ...

  7. Flask(python)异步(ajax)返回json格式数据

    主要讨论两个问题,第一个是关于json.dumps 与jsonify区别,第二个是几种异步的区别(见jQuery中的$.getJSON.$.ajax.$.get.$.post的区别). json.du ...

  8. flask接收post提交的json数据并保存至数据库

    定义数据模型 # 定义数据模型class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(d ...

  9. 第三篇 Flask 中的 request

    第三篇 Flask 中的 request   每个框架中都有处理请求的机制(request),但是每个框架的处理方式和机制是不同的 为了了解Flask的request中都有什么东西,首先我们要写一个前 ...

随机推荐

  1. Android系统框架构

    写此本文是为了对Android系统框架有一个整体的认识和了解,对于开发和测试人员脑子里要有整体认识以便对工作有所帮助. 进入正题 首先Android系统架构采用了分层架构的思想,共分为四层由上到下分: ...

  2. 学习React系列(三)——Refs和Dom

    一.适用于以下场景: 1.控制焦点,文本选择,或者媒体控制 2.触发必要的动画 3.整合第三方dom库 二.不要过度使用ref 如果想通过ref来改变state,那么换一种方式-变量提升可能会更好. ...

  3. 如何用.reg文件操作注册表

    Windows Registry Editor Version 5.00 ;删除值 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpi ...

  4. CAdvisor container monitor

    Now cadvisor is useful as a container montor tool. Not only it can monitor many container level metr ...

  5. webpack构建react项目(一)

    前言 下面是我们使用到技术栈: webpack + react + redux + react-router + react-thunk + ES6 + .... 注意事项: 建议使用npm5.X 或 ...

  6. Mac OS X磁盘重新分区后 BootCamp Windows启动项丢失

    前言 我有一台Mac,装有OS X和Windows两系统,因Windows和OS X都能读写exFAT分区, 故若在Machintosh HD和Windows HD之间开辟一个exFAT分区,可以作为 ...

  7. [WC 2013]糖果公园

    Description 题库链接 给你一棵 \(n\) 个节点,有 \(m\) 种颜色的树.每个节点上有一个颜色.定义一条树上路径的价值为 \[\sum_c V_c(\sum_{i=1}^{tim_c ...

  8. ●BZOJ 3994 [SDOI2015]约数个数和

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3994 题解: 莫比乌斯反演 (先定义这样一个符号[x],如果x为true,则[x]=1,否则 ...

  9. Codeforces 2B. The least round way

    There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a w ...

  10. 主席树(BZOJ2653)

    考虑二分答案,设为k,将大于等于k的元素设为1,小于的设为-1,如果某一段的和>=0,说明这段的中位数>=k. 对于每组询问,二分完后查询新序列的最大子段和即可. 但是不能开n棵线段树,观 ...