如何解决:org.json.JSONException:java.lang.String类型的值GVL7TY无法转换为JSONObject
我试图发出post请求并获取服务器生成的字符串作为响应。我得到这个错误:如何解决:org.json.JSONException:java.lang.String类型的值GVL7TY无法转换为JSONObject,java,android,android-volley,Java,Android,Android Volley,我试图发出post请求并获取服务器生成的字符串作为响应。我得到这个错误:D/error.Response:com.android.volley.ParseError:org.json.JSONException:java.lang.String类型的值GVL7TY无法转换为JSONObject。GVL7TY值是从服务器生成的代码。我是android新手,不知道如何修复它。谢谢你的帮助 private void sendRequest(final String email, final Strin
D/error.Response:com.android.volley.ParseError:org.json.JSONException:java.lang.String类型的值GVL7TY无法转换为JSONObject
。GVL7TY
值是从服务器生成的代码。我是android新手,不知道如何修复它。谢谢你的帮助
private void sendRequest(final String email, final String name,String url,RequestQueue queue) {
JSONObject request = new JSONObject();
try
{
request.put("TeacherEmail", email);
request.put("ClassName", name);
}
catch(Exception e)
{
e.printStackTrace();
}
JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url, request,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject responseObj) {
// response
Log.d("Response", responseObj.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error.Response", error.toString());
}
}
) {
};
queue.add(postRequest);
}
private void sendRequest(最终字符串电子邮件、最终字符串名称、字符串url、请求队列){
JSONObject请求=新建JSONObject();
尝试
{
请求。放置(“教师电子邮件”,电子邮件);
request.put(“ClassName”,name);
}
捕获(例外e)
{
e、 printStackTrace();
}
JsonObjectRequest postRequest=新的JsonObjectRequest(Request.Method.POST,url,Request,
新的Response.Listener(){
@凌驾
public void onResponse(JSONObject responseObj){
//回应
Log.d(“Response”,responseObj.toString());
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Log.d(“Error.Response”,Error.toString());
}
}
) {
};
添加(postRequest);
}
从服务器返回的响应不是有效的json。尝试调试原始响应。Hi!&欢迎使用StackOverflow.,制作一个StringRequest
而不是JsonObjectRequest
。我相信你使用了截击
。