Android获取html响应而不是json响应类型java.lang.String的值<br不能转换为JSONObject

时间:2019-06-07 02:28:11

标签: java android json

您好,我很难找出导致此错误的原因。直到我尝试使用调试并发现,我得到的是HTML响应,而不是json响应。请帮我解决这个问题。

检查此Java代码:

从这一点开始,错误被触发

StringRequest strReq = new StringRequest(Request.Method.POST,
            AppConfig.URL_SUBMIT_CLIENT, response -> {
                Log.d(TAG, "Submission Response: " + response);
                hideDialog();

                try {
                    JSONObject jObj = new JSONObject(response);
                    Log.d("Debug", jObj.toString());
                    boolean error = jObj.getBoolean("success");
                    if (!error) {

                        Toast.makeText(getContext(), "Client successfully submitted.", Toast.LENGTH_LONG).show();

                    } else {

                        // Error occurred in registration. Get the error
                        // message
                        String errorMsg = jObj.getString("error_msg");
                        Toast.makeText(getContext(),
                                errorMsg, Toast.LENGTH_LONG).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

这也是我的hp脚本。我也在某些网站上进行了测试,未发现任何错误,因此,我很确定这里没有问题。我仍将其发布并留给你们,如果有问题,请指出。

require_once __DIR__ . '/DB_Connect.php';

$db = new DB_CONNECT();

$query = mysqli_query("INSERT INTO clientinformation(amountApplied, mop, term, lastname, firstname, middlename, birthdate, age, sex, status, marriageDate, noChildren, nationality, acr, address, cityMunicipality, province, telNo, years, offAddress, offCityMunicipality, offProvince, offTelNo, offYears, busAddress, busCityMunicipality, busProvince, busTelNo, busYears, productServiceOffered) VALUES('$amountApplied','$mop','$term','$lastname','$firstname','$middlename','$birthdate','$age','$sex','$status','$marriageDate','$noChildren','$nationality','$acr','$address','$cityMunicipality','$province','$telNo','$years','$offAddress','$offCityMunicipality','$offProvince','$offTelNo','$offYears','$busAddress','$busCityMunicipality','$busProvince','$busTelNo','$busYears','$productServiceOffered')");

$result = $mysqli->query($query);

if ($result) {

    $response["success"] = 1;
    $response["error_msg"] = "Application successfully made.";

    echo json_encode($response);
} else {

    $response["success"] = 0;
    $response["error_msg"] = "Oops! An error occurred.";

    echo json_encode($response);
}

最后是我的日志

  

W / System.err:org.json.JSONException:值   在org.json.JSON.typeMismatch(JSON.java:112)W / System.err:at   org.json.JSONObject。(JSONObject.java:163)           在org.json.JSONObject。(JSONObject.java:176)           在info.androidhive.bottomnavigation.fragment.ApplicationFragment.lambda $ submitClient $ 4 $ ApplicationFragment(ApplicationFragment.java:253)           在info.androidhive.bottomnavigation.fragment。-$$ Lambda $ ApplicationFragment $ 8jvL3OnFiDofc9nz50lAoSvp9ew.onResponse(未知   资料来源:4)           在com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)           在com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)           在com.android.volley.ExecutorDelivery $ ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)           在android.os.Handler.handleCallback(Handler.java:873)

0 个答案:

没有答案