ich einen Fehler von Post-Parameter zu meinem Server habe, es ist wie meine params sind gar nicht auf meinem Server vorbei ... alles was ich habe ist:Volley, keine Parameter in JsonArrayRequest vorbei
D/Searching: Error: org.json.JSONException: Value {"error_msg":"please choose city to view taxi list"}
dass Nachricht nur kommen, wenn isset ($ _ POST [ 'aus'] so in meinem server
hier mein Code:
// Creating volley request obj
JsonArrayRequest taxiReq = new JsonArrayRequest(Request.Method.POST, url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Taxi taxi = new Taxi();
taxi.settaxiname(obj.getString("taxiname"));
taxi.setThumbnailUrl(obj.getString("image"));
taxi.setdeparture(obj.getString("departure"));
taxi.setarrive(obj.getString("arrive"));
taxi.setseat(obj.getInt("seat"));
taxi.setcost(obj.getInt("cost"));
// adding taxi to taxi array
taxiList.add(taxi);
} catch (JSONException e) {
e.printStackTrace();
}
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error: " + error.getMessage());
}
})
{
@Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
params.put("from", textfrom_btn);
params.put("to", textto_btn);
params.put("seat", totalpassenger);
return params;
}
};
// Adding request to request queue
MyApplication.getInstance().addToRequestQueue(taxiReq);
hier ist die json:
[
{
"image": "http://localhost/androidapp/taxiprofile/1.jpg",
"taxiname": "Taxi 1",
"from": "PTK",
"to": "SGU",
"departure": "08:00:00",
"arrive": "13:00:00",
"seat": 7,
"cost": 12
},
{
"image": "http://localhost/androidapp/taxiprofile/default.jpg",
"taxiname": "Taxi 2",
"from": "PTK",
"to": "SGU",
"departure": "08:00:00",
"arrive": "13:00:00",
"seat": 2,
"cost": 15
},
{
"image": "http://localhost/androidapp/taxiprofile/2.jpg",
"taxiname": "Taxi Untung Selalu",
"from": "PTK",
"to": "SGU",
"departure": "09:00:00",
"arrive": "14:00:00",
"seat": 3,
"cost": 13
}
]
hier mein PHP-Code in meinem Server:
<?php
include './include/DbHandler.php';
$db = new DbHandler();
// json response array
$response = array();
if (isset($_POST['from']) && isset($_POST['to']) && isset($_POST['totalpassenger'])) {
// receiving the post params
$from = $_POST['from'];
$to = $_POST['to'];
$totalpassenger = $_POST['totalpassenger'];
// get the user by email and password
$taxilist = $db->getTaxi($from, $to, $totalpassenger);
if ($taxilist != false) {
// taxi is found
foreach($taxilist as $data){
$response[] = array(
"image" => "http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['REQUEST_URI']).$data["image"],
"taxiname" => $data["taxiname"],
"from" => $data["from"],
"to" => $data["to"],
"departure" => $data["departure"],
"arrive" => $data["arrive"],
"seat" => $data["seat"],
"cost" => $data["cost"]
);
}
echo json_encode($response);
} else {
$response["error_msg"] = "Sorry taxi is not listed";
echo json_encode($response);
}
} else {
$response["error_msg"] = "please choose city to view taxi list";
echo json_encode($response);
}
?>
ist es eine falsche Syntax in Code?
EDIT hier ist die logcat nachdem ich CustomJsonRequest
verwendet03-29 16:11:06.070 25258-25258/com.testing W/EGL_genymotion: eglSurfaceAttrib not implemented
03-29 16:11:06.078 25258-25258/com.testing D/OpenGLRenderer: TextureCache::get: create texture(0xb85fe538): name, size, mSize = 389, 5184, 173360
03-29 16:11:06.082 25258-25258/com.testing D/OpenGLRenderer: TextureCache::get: create texture(0xb8489018): name, size, mSize = 391, 19264, 192624
03-29 16:11:55.714 25258-25258/com.testing D/Searching: []
, wie Sie die Post-Anforderung machen, wenn Sie die oben json Antwort erhalten?Bitte erwähnen Sie die Post-Variablen –
sie sind textfrom_btn = "PTK", textto_btn = "SGU", totalpassenger = 2 ... das sind die Variablen, die ich versucht habe, an meine PHP übergeben ... sind diese was meinen Sie mit Post-Variablen ? – meeftah
können Sie den vollständigen Code Ihres Servers anzeigen? Ihr JsonArrayRequest scheint gültig zu sein – HendraWD