I am trying to make a small example using Volley and Gson. I have the below-posted code. The INTERNET permission was added. Now the URL I have contains JSON data. This JSON data contains several properties and some of the are array of objects. For example,
{
"header":{
"headerTitle":"Check2 Shape Compararison",
"headerDescription":"List of geometric products"
},
"filters":[
"Alle",
"Verfügbar",
"Vorgemerkt"
],
"products":[
{
},
{
}
]
}
Initially, I don't know anything about the structure of the JSON file. What I want to do is, to iterate through the contents of the JSON file to get the name of each property. For example, I want to get the following:
header
filters
products
how this can be achieved using Volley??
error:
private void fetchJSONObjectRequest() {
Log.w(TAG, "<fetchJSONObjectRequest>");
this.mJSONObjectRequest = new JsonObjectRequest(Request.Method.GET, this.BASE_URL, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i(TAG, "<onResponse> response: " + response);
try {
Log.i(TAG, "<onResponse> response: " + response.getJSONArray("products"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
this.mRequestQueue.add(this.mJSONObjectRequest);
}