JsonArrayRequest 返回空值?

问题描述 投票:0回答:0

我正在尝试使用前端的 volley 库和后端的 spring boot 编写一个获取请求。我已经测试了后端并且它工作得很好但是截击的响应是空的,关于为什么会这样有什么想法吗?

这是我的截击请求:

RequestQueue queue = Volley.newRequestQueue(Lobby.this);
        String url = "http://10.0.2.2:8080/lobby/1";
        JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, url, null,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        gameLobby = response;
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(Lobby.this, "ERROR: " + error, Toast.LENGTH_SHORT);
                    }
                }
            );
        queue.add(request);RequestQueue queue = Volley.newRequestQueue(Lobby.this);
        String url = "http://10.0.2.2:8080/lobby/1";
        JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, url, null,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        gameLobby = response;
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(Lobby.this, "ERROR: " + error, Toast.LENGTH_SHORT);
                    }
                }
            );
        queue.add(request);

和我的后端控制器:

  @GetMapping(value = "lobby/{id}", produces = "application/json")
    public ResponseEntity<List<GameLobby>> getLobbyByHost(@PathVariable("id") int hostID) {
        return new ResponseEntity<List<GameLobby>>(gameLobbyRepository.findByHostID(hostID), HttpStatus.OK);
    }

我正在尝试从数据库中获取一个 JSONObject 以在其他地方使用

java android spring-boot android-volley
© www.soinside.com 2019 - 2024. All rights reserved.