amitshekhariitbhu / Fast-Android-Networking

🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
https://outcomeschool.com
Apache License 2.0
5.69k stars 958 forks source link

parseError post message #579

Open eduardofp90 opened 2 years ago

eduardofp90 commented 2 years ago

I have this code and I have always the same error "onError errorDetail : parseError". I have tried to send a simple JSON but it doesn't work. What could be the problem the problem in the code?

btn_ok_mois.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //POST JSON MOIS JSONObject jsonObjectMOIS = new JSONObject(); try { String valueMinMois = et_min_mois.getText().toString(); int finalvalueMinMois = Integer.parseInt(valueMinMois); jsonObjectMOIS.put("minMois", finalvalueMinMois); String valueMaxMois = et_max_mois.getText().toString(); int finalvalueMaxMois = Integer.parseInt(valueMaxMois); jsonObjectMOIS.put("maxMois", finalvalueMaxMois);

            } catch (JSONException e) {
                e.printStackTrace();
            }
            AndroidNetworking.initialize(getApplicationContext());

            AndroidNetworking.post("https://example.com")
                    .addJSONObjectBody(jsonObjectMOIS ) // posting json
                    .setTag("moisture")
                    .setPriority(Priority.MEDIUM)
                    .build()
                    .getAsJSONObject(new JSONObjectRequestListener() {
                        @Override
                        public void onResponse(JSONObject response) {
                            // do anything with response
                            Toast.makeText(Thresholds.this,"OK",Toast.LENGTH_SHORT).show();
                            //tv_test.setText(response.toString());
                        }
                        @Override
                        public void onError(ANError error) {
                            // handle error
                            Toast.makeText(Thresholds.this,"ERROR",Toast.LENGTH_SHORT).show();
                            if (error.getErrorCode() != 0) {
                                Log.d(TAG, "onError errorCode : " + error.getErrorCode());
                                Log.d(TAG, "onError errorBody : " + error.getErrorBody());
                                Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());

                            } else {
                                // error.getErrorDetail() : connectionError, parseError, requestCancelledError
                                Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
                            }
                        }
                    });
        }
    });
eduardofp90 commented 2 years ago

I have to say that for some reason, the server gets the json but in my application I have the error: "onError errorDetail : parseError".