我可以沟通,但我希望在对象中得到一个字幕列表。这是我的代码。
public static void makerequest(){
Thread thread = new Thread() {
@Override
public void run() {
try {
XMLRPCClient client = new XMLRPCClient(new URL("https://api.opensubtitles.org/xml-rpc"));
HashMap ed = (HashMap<Object,String>) client.call("LogIn",username,password,"en",useragent);
String Token = (String) ed.get("token");
Map<String, String> videoProperties = new HashMap<>();
videoProperties.put("sublanguageid", "en");
videoProperties.put("imdbid", "528809");
Object[] videoParams = {videoProperties};
Object[] params = {Token, videoParams};
HashMap test2 = (HashMap<Object,String>) client.call("SearchSubtitles",params);
Object[] d = (Object[]) test2.get("data");
Log.d("diditworkstring", String.valueOf(d));
} catch (Exception ex) {
// Any other exception
Log.d("diditworkexception", String.valueOf(ex));
}
}
};
thread.start();
}
在我的日志中,我得到以下信息:
Log: {seconds=0.188, data=[Ljava.lang.Object;@2ec1b40, status=200 OK}
我以为我会看到一个字幕信息的列表。我在这个响应中看到了(data=Ljava.Object;@23c1b40).该Object中是否有什么东西?
下面是最终成功的代码。我不知道正确的术语,但这是我最好的机会来解释我做错了什么。我试图直接把对象看成一个字符串。用Arrays.asList()查看后,我能够看到数据。然后列表中的每个项目我都投为Map。在那之后,我能够得到改变任何我想要的东西。
希望这对某人有帮助:)
Thread thread = new Thread() {
@Override
public void run() {
try {
// Setup XMLRPC Client
XMLRPCClient client = new XMLRPCClient(new URL("https://api.opensubtitles.org/xml-rpc"));
HashMap ed = (HashMap<Object,String>) client.call("LogIn",username,password,"en",useragent);
// separate my Token from the reply
String Token = (String) ed.get("token");
// setup Parameters for next call to search for subs
Map<String, String> videoProperties = new HashMap<>();
videoProperties.put("sublanguageid", "en");
videoProperties.put("query", "blade 2");
Object[] videoParams = {videoProperties};
Object[] params = {Token, videoParams};
// Make next call include method and Parameters
java.util.HashMap test2 = (HashMap<String,Array>) client.call("SearchSubtitles",params);
// select data key from test2
Object[] d = (Object[]) test2.get("data");
// change d Object to List
List ee = Arrays.asList(d);
// Grab Map from list
Map xx = (Map) ee.get(1);
Log.d("diditworkstring", String.valueOf(xx.get("ZipDownloadLink")));
} catch (Exception ex) {
// Any other exception
Log.d("diditworkexception", String.valueOf(ex));
}
}
};