-3

I'm trying to create a plugin for JDownloader, but I can't get the final link to begin the download.

After I send a POST with the link I want to download, the host sends me this response:

{"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?

Deivid
  • 1
  • 1
    Why regex? We have parsers for that. – Pshemo Feb 24 '18 at 19:22
  • 2
    Possible duplicate of [How to parse JSON in Java](https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – Sparsha Bhattarai Feb 24 '18 at 19:27
  • Pshemo I'm using a code from another JDownloader plugin and editing the fields to match my criteria. This code uses regex to extract the link, so I thought I could use only regex – Deivid Feb 24 '18 at 19:44

1 Answers1

-1

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");
}
Doğukan HAN
  • 123
  • 2
  • 6