我将在我的项目中使用 Ion 库。我正在使用的 api 是这样的: API 链接
我是根据 ion-sample twitter 写的:
Future<JsonArray> VideoLoad;
private void load(){
String MostWatched_Url = "http://www.aparat.com/etc/api/mostviewedvideos/perpage/20";
// don't attempt to load more if a load is already in progress
if (VideoLoad != null && !VideoLoad.isDone() && !VideoLoad.isCancelled()) return;
VideoLoad = Ion.with(this, MostWatched_Url)
.setLogging("Parsvid", Log.DEBUG)
.asJsonArray()
.setCallback(new FutureCallback<JsonArray>() {
@Override
public void onCompleted(Exception e, JsonArray result) {
for (int i = 0; i < result.size(); i++) {
videoAdapter.add(result.get(i).getAsJsonObject());
}
}
});
}
但是当我运行这个我得到这个错误:
05-03 13:58:27.258: D/Parsvid(19020): (629 ms) http://www.aparat.com/etc/api/mostviewedvideos/perpage/20: Caching response
05-03 13:58:27.258: D/Parsvid(19020): (630 ms) http://www.aparat.com/etc/api/mostviewedvideos/perpage/20: Connection successful
05-03 13:58:27.318: D/AndroidRuntime(19020): Shutting down VM
05-03 13:58:27.318: W/dalvikvm(19020): threadid=1: thread exiting with uncaught exception (group=0x417e1c08)
05-03 13:58:27.323: D/Parsvid(19020): (691 ms) http://www.aparat.com/etc/api/mostviewedvideos/perpage/20: Recycling keep-alive socket
05-03 13:58:27.323: E/AndroidRuntime(19020): FATAL EXCEPTION: main
05-03 13:58:27.323: E/AndroidRuntime(19020): Process: com.may3am.parsvid, PID: 19020
05-03 13:58:27.323: E/AndroidRuntime(19020): java.lang.ClassCastException: com.google.gson.JsonObject cannot be cast to com.google.gson.JsonArray
05-03 13:58:27.323: E/AndroidRuntime(19020): at com.may3am.parsvid.MainActivity$2.onCompleted(MainActivity.java:1)
05-03 13:58:27.323: E/AndroidRuntime(19020): at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:96)
05-03 13:58:27.323: E/AndroidRuntime(19020): at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:130)
05-03 13:58:27.323: E/AndroidRuntime(19020): at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:117)
05-03 13:58:27.323: E/AndroidRuntime(19020): at com.koushikdutta.ion.IonRequestBuilder$1.run(IonRequestBuilder.java:239)
05-03 13:58:27.323: E/AndroidRuntime(19020): at com.koushikdutta.async.AsyncServer$RunnableWrapper.run(AsyncServer.java:53)
05-03 13:58:27.323: E/AndroidRuntime(19020): at android.os.Handler.handleCallback(Handler.java:733)
05-03 13:58:27.323: E/AndroidRuntime(19020): at android.os.Handler.dispatchMessage(Handler.java:95)
05-03 13:58:27.323: E/AndroidRuntime(19020): at android.os.Looper.loop(Looper.java:136)
05-03 13:58:27.323: E/AndroidRuntime(19020): at android.app.ActivityThread.main(ActivityThread.java:5476)
05-03 13:58:27.323: E/AndroidRuntime(19020): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 13:58:27.323: E/AndroidRuntime(19020): at java.lang.reflect.Method.invoke(Method.java:515)
05-03 13:58:27.323: E/AndroidRuntime(19020): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
05-03 13:58:27.323: E/AndroidRuntime(19020): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
05-03 13:58:27.323: E/AndroidRuntime(19020): at dalvik.system.NativeStart.main(Native Method)
我的坏在哪里?!我像 ion-sample 一样做到了,当然我api
不需要进行身份验证......而且我没有为我的请求设置标题。