我有Json的RecycleView。
我希望我的按钮可以从特定文件Json下载Url。
如何从Json获取文件Url文件并实现Button按钮下载?
的Json
[
{
"name": "Naruto: Shippuuden",
"description": "It has been two and a half years since Naruto Uzumaki left Konohagakure, the Hidden Leaf Village, for intense training following events which fueled his desire to be stronger. Now Akatsuki, the mysterious organization of elite rogue ninja, is closing in on their grand plan which may threaten the safety of the entire shinobi world.",
"Rating": "8.16",
"episode": 500,
"categorie":"Animation | Drama | Adventure",
"studio":"Studio Pierrot",
"img": "https://myanimelist.cdn-dena.com/images/anime/5/17407.jpg",
"file": "http://androhub.com/demo/demo.pdf"
}]
答案 0 :(得分:0)
首先,您需要将String
转换为JSON
并对其进行解析,您可以使用 org.json 来执行此操作,有关详细信息,请参阅<强> How to convert String to JSONObject in Java 强>
JSONObject jsonObj = new JSONObject("{\"phonetype\":\"N95\",\"cat\":\"WP\"}");
然后您需要下载数据 URL ,有关详细信息,请参阅 How to download and save a file from Internet using Java?
URL website = new URL("http://www.website.com/information.asp");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("information.html");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);