gpt4 book ai didi

java - Volley 抽射。发送 JSONObject 作为参数

转载 作者:行者123 更新时间:2023-12-02 11:01:03 25 4
gpt4 key购买 nike

我已经用谷歌搜索并研究了其他SO文章。但没有任何帮助。请帮我找出问题所在。我所做的是我想从 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。
  • 然后要求网络服务开发人员解决此问题。
  • 如果服务器端的响应不是 JSON,则将 JsonObjectRequest 更改为 StringRequest

关于java - Volley 抽射。发送 JSONObject 作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51317986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com