排球。发送 JSONObject 作为参数
Volley. Sending JSONObject as parameter
我用谷歌搜索并查看了其他 SO 文章。但 none 有所帮助。请帮我确定是什么问题。我所做的是我想从 StringRequest
更改为 JsonObjectRequest
我收到这个错误:
com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of
我的代码
RequestQueue queue = Volley.newRequestQueue(this);
String url = "http://"+employee.get_ip_address()+"/NextrackAndroid/authenticate.php";
Log.d("TAG", "URL : "+ url);
JSONObject obj = new JSONObject();
try {
obj.put("id", id.toString());
obj.put("deviceID", deviceID.toString());
Log.d("TAG", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,url,obj,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("TAG", "onResponse : " + response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("TAG", "onErrorResponse : " + error.toString());
error.printStackTrace();
}
}){
/** Passing some request headers* */
@Override
public Map getHeaders() throws AuthFailureError {
HashMap headers = new HashMap();
headers.put("Content-Type", "application/json");
return headers;
}
};
queue.add(jsObjRequest);
com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of
这不是你的附带问题。
当您的回复不是 JSONObject
时,此问题仍然存在。所以你的代码无法处理它。因为您已将 JsonObjectRequest
作为响应处理程序。
解决这个问题。
- 检查其在 Postman 上的响应或向 Web 服务开发人员询问。
- 您会发现Web-Service 的响应并不完美JSON。
- 然后请 Web 服务开发人员解决此问题。
- 或者如果响应不是来自服务器端的 JSON,则将
JsonObjectRequest
更改为 StringRequest
。
我用谷歌搜索并查看了其他 SO 文章。但 none 有所帮助。请帮我确定是什么问题。我所做的是我想从 StringRequest
更改为 JsonObjectRequest
我收到这个错误:
com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of
我的代码
RequestQueue queue = Volley.newRequestQueue(this);
String url = "http://"+employee.get_ip_address()+"/NextrackAndroid/authenticate.php";
Log.d("TAG", "URL : "+ url);
JSONObject obj = new JSONObject();
try {
obj.put("id", id.toString());
obj.put("deviceID", deviceID.toString());
Log.d("TAG", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,url,obj,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("TAG", "onResponse : " + response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("TAG", "onErrorResponse : " + error.toString());
error.printStackTrace();
}
}){
/** Passing some request headers* */
@Override
public Map getHeaders() throws AuthFailureError {
HashMap headers = new HashMap();
headers.put("Content-Type", "application/json");
return headers;
}
};
queue.add(jsObjRequest);
com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of
这不是你的附带问题。
当您的回复不是 JSONObject
时,此问题仍然存在。所以你的代码无法处理它。因为您已将 JsonObjectRequest
作为响应处理程序。
解决这个问题。
- 检查其在 Postman 上的响应或向 Web 服务开发人员询问。
- 您会发现Web-Service 的响应并不完美JSON。
- 然后请 Web 服务开发人员解决此问题。
- 或者如果响应不是来自服务器端的 JSON,则将
JsonObjectRequest
更改为StringRequest
。