我正在使用WP REST API V2为Wordpress网站制作应用程序。我可以使用API检索类别数据,但是当我尝试检索帖子或媒体时,没有任何反应。
private void sendJsonRequest(){
Log.i("Warlock","Entered sendJsonRequest");
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(URL_XBOX,new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.i("Warlock","Entered onResponse");
try {
Log.i("Warlock",response.toString());
parseJsonArray(response);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonArrayRequest);
}
private void parseJsonArray(JSONArray response) throws JSONException {
Log.i("Warlock","Entered parseJsonArray");
if (response == null || response.length() == 0){
return;
}
for(int i=0; i < response.length(); i++){
JSONObject jsonObject = response.getJSONObject(i);
int id = Integer.getInteger(jsonObject.getString(KEY_ID));
//String title = jsonObject.getString(KEY_TITLE);
JSONObject jsonTitle = jsonObject.getJSONObject(KEY_TITLE);
JSONObject jsonContent = jsonObject.getJSONObject(KEY_CONTENT);
JSONObject jsonExcerpt = jsonObject.getJSONObject(KEY_EXCERPT);
String title = jsonTitle.getString("rendered");
String content = jsonContent.getString("rendered");
String excerpt = jsonExcerpt.getString("rendered");
String featuredMedia = jsonObject.getString(KEY_FEATURED_MEDIA);
WordPressPost newPost = new WordPressPost();
newPost.setId(id);
newPost.setTitle(title);
newPost.setContent(content);
newPost.setExcrept(excerpt);
newPost.setFeaturedMedia(featuredMedia);
listPosts.add(newPost);
}
Log.i("Warlock",listPosts.toString());
text.setText(listPosts.toString());
}
这是日志输出:
05-04 05:31:10.374 26586-26586/com.warlock31.badcontroller W/System: ClassLoader referenced unknown path: /data/app/com.warlock31.badcontroller-1/lib/x86
05-04 05:31:11.350 26586-26586/com.warlock31.badcontroller W/System: ClassLoader referenced unknown path: /data/app/com.warlock31.badcontroller-1/lib/x86
05-04 05:31:11.564 26586-26586/com.warlock31.badcontroller I/Warlock: Constructor Called
05-04 05:31:11.596 26586-26640/com.warlock31.badcontroller D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[ 05-04 05:31:11.600 26586:26586 D/ ]
HostConnection::get() New Host Connection established 0xe7c93d70, tid 26586
05-04 05:31:11.630 26586-26586/com.warlock31.badcontroller I/Warlock: Entered sendJsonRequest
05-04 05:31:11.649 26586-26640/com.warlock31.badcontroller D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
05-04 05:31:11.650 26586-26640/com.warlock31.badcontroller D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
05-04 05:31:11.656 26586-26640/com.warlock31.badcontroller D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so
[ 05-04 05:31:11.662 26586:26640 D/ ]
HostConnection::get() New Host Connection established 0xf0477340, tid 26640
05-04 05:31:11.679 26586-26640/com.warlock31.badcontroller I/OpenGLRenderer: Initialized EGL, version 1.4
05-04 05:31:11.776 26586-26640/com.warlock31.badcontroller W/EGL_emulation: eglSurfaceAttrib not implemented
05-04 05:31:11.776 26586-26640/com.warlock31.badcontroller W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe0b87e80, error=EGL_SUCCESS
05-04 05:31:11.828 26586-26586/com.warlock31.badcontroller E/RecyclerView: No adapter attached; skipping layout
05-04 05:31:11.859 26586-26586/com.warlock31.badcontroller E/RecyclerView: No adapter attached; skipping layout
[ 05-04 05:31:12.034 87: 87 D/ ]
Socket deconnection