zoukankan      html  css  js  c++  java
  • Request JSON

    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.

  • 相关阅读:
    只允许在input框输入文字,不能输入数字和其他字符
    阻止用户在input框输入数字
    centos 7.2安装和配置MongoDB
    Python基础
    Python小练习008
    Python小练习007
    Python小练习006
    Python错误集锦
    Python和MongoDB
    MongoDB笔记
  • 原文地址:https://www.cnblogs.com/xiangnan/p/5513542.html
Copyright © 2011-2022 走看看