我正在使用 volley JSONrequest 从我的 android 应用程序向 ESP32 服务器发送 Wifi 凭据。我能够在 ESP32 服务器中获取请求,但在发送响应后,我在 volley 中收到了 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);
我server.send(200, "application/json", "{\"connected\":\"True\"}");
从 ESP32 发送。