问题
I got this json
array
:
{
"conferences": [
{
"id": 1,
"name": "Conferencia Magistral",
"description": "Conferencia bien chingona lalala",
"speaker": "Jorge",
"biography": "bioo",
"place": {
"name": "Auditorio",
"description": "Presentacion de peliculas y documentales"
},
"date": "31/10/2015",
"time": "16:00"
}
]
}
And this is my code in Android Studio:
queue = Volley.newRequestQueue(this);
JsonArrayRequest JsonRequest = new JsonArrayRequest(Request.Method.GET, url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
for (int i = 1, count = response.length(); i < count; i++) {
EventInfo eventInfo = new EventInfo();
eventInfo.name = response.getJSONObject(i).getString("name");
eventInfo.date = response.getJSONObject(i).getString("date");
eventInfo.hour_event = response.getJSONObject(i).getString("time");
eventInfo.link="http://www.tallertoa.com/v1/files/gimgs/7_botanico-lamina-21.jpg";
eventInfo.description = response.getJSONObject(i).getString("description");
eventInfos.add(eventInfo);
}
recList.setAdapter(adapter);
Log.e("JSON", response.toString());
} catch (JSONException e) {
showErrorDialog("error Json parser", "error al parsear objeto Json Evento");
Log.e("json error",e.toString());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
queue.add(JsonRequest);
}
So, i cant parse this Json Array, I've done this but with POST method, so i was wondering if any of you could tell me how to do this using volley
回答1:
{
"conferences": [
{
"id": 1,
"name": "Conferencia Magistral",
"description": "Conferencia bien chingona lalala",
"speaker": "Jorge",
"biography": "bioo",
"place": {
"name": "Auditorio",
"description": "Presentacion de peliculas y documentales"
},
"date": "31/10/2015",
"time": "16:00"
}
]
}
Firstly, this is a JSONObject, not a JSONArray. You can go here and here for more information
JSONObject: ...A string beginning with { (left brace) and ending with } (right brace).
JSONArray: ...A string that begins with [ (left bracket) and ends with ] (right bracket).
As a result, you can use a JsonObjectRequest
instead of JsonArrayRequest
Hope this helps!
来源:https://stackoverflow.com/questions/32959137/parsing-json-using-get-method-with-volley-in-android-studio