未知的 JSONException:无法将 java.lang.String 类型的值取消注册转换为 JSONObject

问题描述

我正在使用 volley JSONrequest 从我的 android 应用程序向 ESP32 服务器发送 Wifi 凭据。我能够在 ESP32 服务器中收到请求,但是在发送响应后,我收到了一个 VolleyError。我在其他任何地方都找不到这个错误

org.json.JSONException: Value Deregistered of type java.lang.String cannot be converted to JSONObject

这是我的代码

JSONObject jsonBody = new JSONObject();
jsonBody.put("ssid",ssid);
jsonBody.put("password",password);
jsonBody.put("fbtoken",FirebaseInstanceId.getInstance().getToken());
jsonBody.put("uid",anonUser.getUid());
       
Log.d("WifiCredential","Post: "+jsonBody.toString());
JsonObjectRequest credetialPost = new JsonObjectRequest
(Request.Method.POST,URL,jsonBody,new Response.Listener<JSONObject>() {

      @Override
      public void onResponse(JSONObject response) {

          try {

              boolean connected = response.getBoolean("connected");
              if (connected){
                  debugRef.child("CredSend").child("Connected").setValue(true);
                  LAN_IP = response.getString("ip");
                  Log.d("WifiCredential","Connected: "+LAN_IP);
                  Toast.makeText(MainActivity.this,"LAN Connected",Toast.LENGTH_LONG).show();     
                  }
              } catch (JSONException e) {
                            Log.d("WifiCredential","JSON Error: " + e.getMessage());
                            Log.d("WifiCredential","Response: "+response);
                            e.printstacktrace();
                        }
                    }
                },new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // Todo: Handle error
                        Log.d("WifiCredential","Error Last: "+Objects.requireNonNull(error.getMessage()));
                   
                    }
                });

        credetialPost.setRetryPolicy(new DefaultRetryPolicy(
                10000,1,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        requestQueue.add(credetialPost);

我正在从 ESP32 发送 server.send(200,"application/json","{\"connected\":\"True\"}");

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)