Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在不发送JSON请求的情况下从服务器获取JSON_Android_Json_Android Volley - Fatal编程技术网

Android 如何在不发送JSON请求的情况下从服务器获取JSON

Android 如何在不发送JSON请求的情况下从服务器获取JSON,android,json,android-volley,Android,Json,Android Volley,我需要帮助。 我使用volley将json对象发送到RESTAPI服务器。我从这个API向我的应用程序(json)获取数据。它的工作很好: JsonObjectRequest mJsonObjectRequest=新的JsonObjectRequest(Request.Method.POST、url、JSONDATA、JSONListener、errorListener) … 现在我想在不使用JSONDATA的情况下发送请求(我不能设置null)。这是为了全球价值观。没有必要发送一些数据。我不知

我需要帮助。 我使用volley将json对象发送到RESTAPI服务器。我从这个API向我的应用程序(json)获取数据。它的工作很好:

JsonObjectRequest mJsonObjectRequest=新的JsonObjectRequest(Request.Method.POST、url、JSONDATA、JSONListener、errorListener)
…


现在我想在不使用JSONDATA的情况下发送请求(我不能设置null)。这是为了全球价值观。没有必要发送一些数据。我不知道如何发送这个请求。你能帮我吗?

在我明白你的问题之前,我的答案是

StringRequest distRequest=new StringRequest(Request.Method.POST, YOUR_URL, new Response.Listener<String>() {
             @Override             public void onResponse(String response) {      
 Toast.makeText(MainActivity.this, " "+response.toString, Toast.LENGTH_SHORT).show();           

            }
        }, new Response.ErrorListener() {
            @Override
           public void onErrorResponse(VolleyError error) {
               progressDialog.dismiss();
                Toast.makeText(MainActivity.this, " "+error.toString, Toast.LENGTH_SHORT).show();

            }
        });
        RequestQueue distQueue=Volley.newRequestQueue(this);
         distQueue.add(distRequest);
    }
StringRequest distRequest=new-StringRequest(Request.Method.POST,您的_URL,new-Response.Listener()){
@重写公共void onResponse(字符串响应){
Toast.makeText(MainActivity.this,“+response.toString,Toast.LENGTH_SHORT.show();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
progressDialog.disclose();
Toast.makeText(MainActivity.this,“+error.toString,Toast.LENGTH_SHORT.show();
}
});
RequestQueue distQueue=Volley.newRequestQueue(this);
添加(distRequest);
}

在我理解你的问题之前,我的答案是

StringRequest distRequest=new StringRequest(Request.Method.POST, YOUR_URL, new Response.Listener<String>() {
             @Override             public void onResponse(String response) {      
 Toast.makeText(MainActivity.this, " "+response.toString, Toast.LENGTH_SHORT).show();           

            }
        }, new Response.ErrorListener() {
            @Override
           public void onErrorResponse(VolleyError error) {
               progressDialog.dismiss();
                Toast.makeText(MainActivity.this, " "+error.toString, Toast.LENGTH_SHORT).show();

            }
        });
        RequestQueue distQueue=Volley.newRequestQueue(this);
         distQueue.add(distRequest);
    }
StringRequest distRequest=new-StringRequest(Request.Method.POST,您的_URL,new-Response.Listener()){
@重写公共void onResponse(字符串响应){
Toast.makeText(MainActivity.this,“+response.toString,Toast.LENGTH_SHORT.show();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
progressDialog.disclose();
Toast.makeText(MainActivity.this,“+error.toString,Toast.LENGTH_SHORT.show();
}
});
RequestQueue distQueue=Volley.newRequestQueue(this);
添加(distRequest);
}
试试这个:

// prepare the Request
JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, null,
        new Response.Listener<JSONObject>() 
        {
            @Override
            public void onResponse(JSONObject response) {   
                            // display response     
                Log.d("Response", response.toString());
            }
        }, 
        new Response.ErrorListener() 
        {
             @Override
             public void onErrorResponse(VolleyError error) {            
                Log.d("Error.Response", response);
           }
        }
    );

    // add it to the RequestQueue   
    queue.add(getRequest);
//准备请求
JsonObjectRequest getRequest=新的JsonObjectRequest(Request.Method.GET,url,null,
新的Response.Listener()
{
@凌驾
public void onResponse(JSONObject response){
//显示响应
Log.d(“Response”,Response.toString());
}
}, 
新的Response.ErrorListener()
{
@凌驾
公共无效onErrorResponse(截击错误){
Log.d(“错误.响应”,响应);
}
}
);
//将其添加到RequestQueue
添加(getRequest);
试试这个:

// prepare the Request
JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, null,
        new Response.Listener<JSONObject>() 
        {
            @Override
            public void onResponse(JSONObject response) {   
                            // display response     
                Log.d("Response", response.toString());
            }
        }, 
        new Response.ErrorListener() 
        {
             @Override
             public void onErrorResponse(VolleyError error) {            
                Log.d("Error.Response", response);
           }
        }
    );

    // add it to the RequestQueue   
    queue.add(getRequest);
//准备请求
JsonObjectRequest getRequest=新的JsonObjectRequest(Request.Method.GET,url,null,
新的Response.Listener()
{
@凌驾
public void onResponse(JSONObject response){
//显示响应
Log.d(“Response”,Response.toString());
}
}, 
新的Response.ErrorListener()
{
@凌驾
公共无效onErrorResponse(截击错误){
Log.d(“错误.响应”,响应);
}
}
);
//将其添加到RequestQueue
添加(getRequest);

添加您的代码如何点击服务?在这种情况下,您需要发送一个GET请求,我认为您不需要传递数据-只是URL。添加您的代码如何点击服务?在这种情况下,您需要发送一个GET请求,我认为您不需要传递数据-只是URL。