Dies ist mein Code zum Anfordern des JSONObject. Während der Arbeit mit der String-Anfrage funktionierte es perfekt, aber ich brauche JSONObject.Kann kein JSON-Objekt für JSONObjectRequest mit Volley empfangen
Map<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("password", password);
params.put("request", "login");
JSONObject jsonObj = new JSONObject(params);
String url="http://example.com/android/login.php";
JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url,jsonObj,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response) {
// response
// JSONObject json = JSONObject.toJson(response);
// Toast.makeText(Login.this, "Your ID is ."+response, Toast.LENGTH_LONG).show();
//Log.d("Response", response.toString());
Intent r = new Intent(Login.this,Cus_home.class);
startActivity(r);
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// error
Log.d("Error.Response", error.toString());
}
}
);
mRequestQueue.add(postRequest);
die Ausgabe der API-Ausgabe Bei der Kontrolle ist: [{"id":"77","type":"1"}]
aber nach dem Android-Code ausgeführt wird, erhalte ich diese
Error.Response: com.android.volley.ParseError: org.json.JSONException: End of input at character 1 of
Jede Hilfe Hilfe wirklich
geschätzt
aussehen würde Schon gesehen http://stackoverflow.com/questions/23220695/send-post-request-mit-json-daten-using-volley? Es schlägt vor, diese Syntax wie folgt zu verwenden: 'final JSONObject jsonBody = neues JSONObject (" {\ "type \": \ "example \"} ");' –
Ich habe Probleme beim Empfang von JsonObject. Nicht sicher, ob mir das helfen kann –
@SimonPhoenix JsonObject stammt aus meinen Eingabefeldern. Bitte schlagen Sie etwas mehr vor –