简体   繁体   English

如何使用正则表达式从 JSON 中提取下载链接?

[英]How to extract a download link from a JSON using Regex?

I'm trying to create a plugin for JDownloader, but I can't get the final link to begin the download.我正在尝试为 JDownloader 创建一个插件,但我无法获得开始下载的最终链接。

After I send a POST with the link I want to download, the host sends me this response:在我发送带有我要下载的链接的 POST 后,主机向我发送此响应:

{"error":"0","link":"http:\/\/originalhost.net\/file\/ba0jf5t8","type":"2","name":"test.zip","size":"5 MB","date":"31\/12\/2017 15:56","until":"31\/12\/2018 15:56","download":"http:\/\/beta.generatedlink.net\/originalhost\/randomuuid\/test.zip","password":""}

and I want to use Regex to extract only:我只想使用正则表达式来提取:

http://beta.generatedlink.net/originalhost/randomuuid/test.zip

I have tried some examples I found online but I couldn't get to work我尝试了一些我在网上找到的例子,但我无法开始工作

How can I do this?我怎样才能做到这一点?

This gets value for given key.这获取给定键的值。

String jsonData = "" // fill it with your data
String pattern = "(?:\"download\":\")(.*?)(?:\")"; // download is key
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(jsonData);
if (m.find()) {
    System.out.println("Found value: " + m.group(0));
} else {
    System.out.println("NO MATCH");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM