【发布时间】:2020-04-26 20:13:40
【问题描述】:
我尝试将一些 JSON 值发布到我的 mysql 表中,但我不断收到 JSONException(字符 0 处的输入结束)。我已经尝试使用邮递员,它工作正常,但是当我尝试在我的安卓设备中运行它时出现错误这是我的 java 代码
String url = "//MY url goes here//";
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, response -> {
try {
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("message");
Toast.makeText(getAplicationContext, request_type + " " +success, Toast.LENGTH_SHORT).show();
progressBar1.setVisibility(View.INVISIBLE);
if (success.equals("Request sent Successfully")) {
Toast.makeText(getAplicationContext.this, request_type +" Request Sent Successfully", Toast.LENGTH_SHORT).show();
progressBar1.setVisibility(View.INVISIBLE);
} else {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Exception " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}, error -> Toast.makeText(getApplicationContext(), "Error :: " + error.getMessage(), Toast.LENGTH_SHORT).show()) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("status", status);
params.put("type", type);
params.put("req", request);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
我能够使用邮递员成功地向其发布数据,但它在 android 中抛出 JsonException 错误,所以我认为它必须来自我上面的代码。任何帮助或建议将不胜感激 谢谢
【问题讨论】:
标签: android json android-volley