Nun lange Geschichte kurz ich dieser Art von Problem konfrontiert, Volley Anfrage an meine Server zu senden, Im Versuch, das mit json Array antwortet:Keine Antwort von jsonArray Anfrage
{
"images": [{
"product_serial_num": "1",
"product_title": "Abbadon",
"product_img": "http://1.2.3.4/android/uploads/1.jpg",
"product_price": "750",
"product_description": "The destroyer"
}]
}
aber egal was ich versuchte mich noch erhalten Volley Antwortfehler, mein Volley Anfrage: es funktioniert, nur die Array-Chaos Dinge für mich
requestQueue = Volley.newRequestQueue(getActivity());
//JsonArrayRequest of volley
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(MY_URL ,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
//parseData to parse the json response
parseData(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//If an error occurs that means end of the list has reached
Toast.makeText(getActivity(), "No More Items Available", Toast.LENGTH_SHORT).show();
}
});
requestQueue.add(jsonArrayRequest);
die seltsame Sache, dass mit Volley String Anfrage.
EDIT:
wie auch immer diese Weise kann ich meine Array tun bekommen Futter mit:
private void getData() {
//Adding the method to the queue by calling the method getDataFromServer
requestQueue.add(getDataFromServer(requestCount));
//Incrementing the request counter
requestCount++;
}
//Request to get json from server we are passing an integer here
//This integer will used to specify the page number for the request ?page = requestcount
//This method would return a JsonArrayRequest that will be added to the request queue
private JsonArrayRequest getDataFromServer(int requestCount) {
//JsonArrayRequest of volley
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(URL_INDEX + String.valueOf(requestCount),
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
//Calling method parseData to parse the json response
parseData(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//If an error occurs that means end of the list has reached
Toast.makeText(getActivity(), "No More Items Available", Toast.LENGTH_SHORT).show();
}
});
//Returning the request
return jsonArrayRequest;
}
Thank you!
Antwort Json ist JSONObject nicht JSONArray. Verwenden 'JsonObjectRequest' von Volley statt' JsonArrayRequest' –
Objekt und String beide arbeiten, tut nur Array – 2Stoned
Da Antworttyp JSONObject –