0
Hello,
I’m sending POST to an archive PHP using the library Volley. Everything goes well until the application tries to show the answer to the user. In the file PHP use the command echo 'user created';. The application shows the following error:
Error: com.android.Volley.Parseerror: org.json.Jsonexception: Value usuario_created of type java.lang.String cannot be converted to Jsonobject
I apologize for not being the logcat, but is that I am testing the application on a real mobile.
Here’s the code I use to send the POST.
queue = Volley.newRequestQueue(this);
map.put("nickname", userName);
request = new JsonObjectRequest(
Request.Method.POST,
url,
new JSONObject(map),
new Response.Listener<JSONObject>(){
@Override
public void onResponse(JSONObject response){
Toast.makeText(ctx, "Resposta: " + response, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
Toast.makeText(ctx, "Erro: " + error, Toast.LENGTH_LONG).show();
}
}
);
queue.add(request);
Have you checked whether you are receiving a value in JSON format? see this post => http://stackoverflow.com/questions/30196601/volley-string-cannot-be-converted-to-jsonobject
– Jeiferson
I’m not passing in Json format, buddy, I just echo the text. But I tried printing in json format, I also tried to add header as application/json. There were two possible solutions I found online, but none of them helped.
– Mt. Y
was looking here and it is not advisable to use a Jsonobjectrequest to receive a string
– Jeiferson
How it should be done?
– Mt. Y