Estoy usando volley para extraer las categorías y publicaciones de un sitio de wordpress para mostrarlas en una aplicación de Android, primero las categorías me responden bien, mientras agrego las categorías a una lista, intento extraer las publicaciones para otra lista , pero vuelve []uso la url en el navegador y devuelve los valores ok, ayúdame, ¿qué estoy haciendo mal?
public void extractCategories() { String URL = getResources().getString(R.string.categories_url);
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, URL, null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAGC, "onResponse: " + response.toString());
for (int i = 0; i < response.length(); i++) {
try {
Category c = new Category();
JSONObject jsonObjectData = response.getJSONObject(i);
// extract the id
c.setId(jsonObjectData.getInt("id"));
// extract the name
c.setName(jsonObjectData.getString("name"));
//extract the parent
c.setParent(jsonObjectData.getInt("parent"));
//extract the parent
c.setCount(jsonObjectData.getInt("count"));
cat_list.add(c);
extractPosts(i); //here I call the function to extract the posts
} catch (JSONException e) {
e.printStackTrace();
}
}
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
MySingletonVolley.getInstance(getBaseContext()).addToRequestQueue(request);
}
public void extractPosts(int i) {
int cont = 0;
String URL = getResources().getString(R.string.posts_url);
int cant_post_real = this.cat_list.get(i).getCount();
int page = 0;
while ( cant_post_real > 0) {
page++;
String complete_url = URL + page + "&categories=" + this.cat_list.get(i).getId();
JsonArrayRequest request1 = new JsonArrayRequest(Request.Method.GET, complete_url, null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, "onResponse: " + response.toString());
for (int k = 0; k < response.length(); k++) {
try {
Post p = new Post();
JSONObject jsonObjectData = response.getJSONObject(k);
// extract the title
JSONObject titleObject = jsonObjectData.getJSONObject("title");
p.setTitle(titleObject.getString("rendered"));
// extract the content
JSONObject contentObject = jsonObjectData.getJSONObject("content");
p.setContent(contentObject.getString("rendered"));
//extract the excerpt
JSONObject excerptObject = jsonObjectData.getJSONObject("excerpt");
p.setExcerpt(excerptObject.getString("rendered"));
// extract feature image
JSONObject embeddedObject = jsonObjectData.getJSONObject("_embedded");
JSONArray wpfeaturemediaArray = embeddedObject.getJSONArray("wp:featuredmedia");
JSONObject firstElement = wpfeaturemediaArray.getJSONObject(0);
p.setFeature_image(firstElement.getString("source_url"));
posts.add(p);
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
cant_post_real = cant_post_real - 10;
MySingletonVolley.getInstance(getBaseContext()).addToRequestQueue(request1);
}
}
.