我从您的示例代码中假设您正在使用适用于 Android 0.10.10 的 Deezer SDK。
JsonRequestListener 能够解析许多常见请求,但尚未解析所有可用的 API 请求,并且您正在使用的请求尚未正确处理。不幸的是,此版本的 SDK 存在一个小错误,导致您遇到的回调缺失。
这是一个示例侦听器,您可以使用它来解析 API 对此特定请求的响应:
RequestListener listener = new RequestListener() {
@SuppressWarnings("unchecked")
@Override
public void onComplete(String response, Object requestId) {
List<Track> tracks;
List<Artist> artists;
List<Album> albums;
try {
JSONObject json = new JSONObject(response);
tracks = (PaginatedList<Track>) JsonUtils
.deserializeObject(json.optJSONObject("tracks"));
artists = (PaginatedList<Artist>) JsonUtils
.deserializeObject(json.optJSONObject("artists"));
albums = (PaginatedList<Album>) JsonUtils
.deserializeObject(json.optJSONObject("albums"));
} catch (Exception e) {
tracks = Collections.emptyList();
artists = Collections.emptyList();
albums = Collections.emptyList();
e.printStackTrace();
}
Log.i("Json",
"Parsed " + tracks.size() + " tracks, " + albums.size()
+ " albums and " + artists.size() + " artists");
}
@Override
public void onOAuthException(OAuthException e, Object requestId) {
e.printStackTrace();
}
@Override
public void onMalformedURLException(MalformedURLException e, Object requestId) {
e.printStackTrace();
}
@Override
public void onIOException(IOException e, Object requestId) {
e.printStackTrace();
}
@Override
public void onDeezerError(DeezerError e, Object requestId) {
e.printStackTrace();
}
};
DeezerRequest request = new DeezerRequest("editorial/0/charts");
AsyncDeezerTask task = new AsyncDeezerTask(mConnect, mListener);
task.execute(request);