小编fuj*_*su4的帖子

无法解析符号"方法"

我试图在Android代码中做一个简单的GET请求,我只是从Volley的官方网站复制了代码,但我得到一个错误说:"无法解析符号"方法"".

我的代码是这样的:

public void onReceive(final Context context, Intent intent) {
    // Instantiate the RequestQueue.
    RequestQueue queue = Volley.newRequestQueue(context);
    String url = ***** ; // my URL

    // Request a string response from the provided URL.
    StringRequest stringRequest = new StringRequest(DownloadManager.Request.Method.GET, url,
            new Response.Listener<String>() {  //the error is in THIS line
                @Override
                public void onResponse(String response) {
                    // Display the first 500 characters of the response string.
                    Toast.makeText(context, "Response is: " + response.substring(0,500), Toast.LENGTH_LONG).show();

                }
            }, new Response.ErrorListener() {
        @Override
        public …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-volley

5
推荐指数
1
解决办法
7750
查看次数

使用Volley使用JSONArray发送POST请求

我想在Android中发送一个简单的POST请求,其中一个正文等于:

[
 {
  "value": 1
 }
]
Run Code Online (Sandbox Code Playgroud)

我尝试在Android中使用Volley库,这是我的代码:

// the jsonArray that I want to POST    
String json = "[{\"value\": 1}]";
JSONArray jsonBody = null;
try {
     jsonBody = new JSONArray(json);
    } catch (JSONException e) {
                               e.printStackTrace();
                              }
final JSONArray finalJsonBody = jsonBody;

// starting the request
final RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
JsonObjectRequest request = 
new JsonObjectRequest(com.android.volley.Request.Method.POST,"https://...",null,

new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {
Log.d("mytag", "Response is: " + response);}},
new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) …
Run Code Online (Sandbox Code Playgroud)

android json request android-volley

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×2

android-volley ×2

android-studio ×1

json ×1

request ×1