【发布时间】:2021-03-06 06:11:40
【问题描述】:
我正在尝试使用 json 文件从 url 获取 youtube 标题,但我没有得到任何结果,我也没有得到任何异常。我尝试在吐司消息中吐司异常为空/空白。任何人都可以帮助我。我的代码在这里...
String link = youtube url;
URL embededURL = null;
try {
embededURL = new URL("http://www.youtube.com/oembed?url=" + link + "&format=json");
} catch (MalformedURLException e) {
e.printStackTrace();
makeToast(e.getMessage());
}
try {
title = new JSONObject(IOUtils.toString(embededURL)).getString("title");
} catch (JSONException e) {
e.printStackTrace();
makeToast(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
makeToast(e.getMessage());
}
makeToast(title);
【问题讨论】:
-
您使用的是哪个版本的 Apache Commons IO?
IOUtils.toString(URL)似乎自 2.5 版以来已被弃用。以下是最新版本列表:mvnrepository.com/artifact/commons-io/commons-io