JsonObjectRequest和JsonArrayRequest(均为JsonRequest的子类),指定一个URL而且从响应中获取JSON对象和数组。json
Volley提供如下类用于JSON 请求:数组
两个class都以共同的类JsonRequest为基类。下面的代码段将获取JSON返回,并将其显示为UI中的文本:ide
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);