如何使用Regex从JSON中提取下载链接?

时间:2018-02-24 19:21:07

标签: java json regex

我正在尝试为JDownloader创建一个插件,但我无法获得开始下载的最终链接。

发送包含我要下载的链接的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":""}

我想使用正则表达式仅提取:

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

我尝试了一些我在网上找到的例子,但我无法上班

我该怎么做?

1 个答案:

答案 0 :(得分:-1)

这为给定密钥获取值。

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");
}