Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.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
我正在尝试获取JSON数据,并将其用于android应用程序,使用volley库,但它不起作用,即使我无法找到代码中的错误_Android_Json_Android Volley - Fatal编程技术网

我正在尝试获取JSON数据,并将其用于android应用程序,使用volley库,但它不起作用,即使我无法找到代码中的错误

我正在尝试获取JSON数据,并将其用于android应用程序,使用volley库,但它不起作用,即使我无法找到代码中的错误,android,json,android-volley,Android,Json,Android Volley,//在这里,我们从setOnClickListener方法调用一个方法调用jsoneParse private void jsonParse(){ //在这里我插入了我的Url String url = "https://api.myjson.com/bins/hrtn6"; //json对象请求 final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, null,

//在这里,我们从setOnClickListener方法调用一个方法调用jsoneParse

private void jsonParse(){
//在这里我插入了我的Url

    String url = "https://api.myjson.com/bins/hrtn6";   
//json对象请求

    final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

            try {
//这里,我们将请求插入到请求队列中

    mQueue.add(request);
}

只需像这样将您的
请求方法更改为
get

final JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
.
.
.
final JsonObjectRequest request=new JsonObjectRequest(request.Method.GET,url,null,new Response.Listener()){
.
.
.
更改此选项

 final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
final JsonObjectRequest request=new JsonObjectRequest(request.Method.POST,url,null,new Response.Listener()){
为此:

final JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
final JsonObjectRequest request=new JsonObjectRequest(request.Method.GET,url,null,new Response.Listener()){

将requestbody设置为string而不是null (url后的参数)

final JsonObjectRequest request=new JsonObjectRequest(request.Method.POST,url,”,new Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
.....
}
}
这对我有帮助, 希望这能帮助你,
快乐编码

我认为json解析没有任何错误。错误到底是什么?
 final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
final JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, "", new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                .....
            }

     }