Skip to content

Instantly share code, notes, and snippets.

@DV8FromTheWorld
Created July 3, 2014 19:37
Show Gist options
  • Select an option

  • Save DV8FromTheWorld/03dda571e112ee4f3fd5 to your computer and use it in GitHub Desktop.

Select an option

Save DV8FromTheWorld/03dda571e112ee4f3fd5 to your computer and use it in GitHub Desktop.
getId and getLink
/**
* Uses Regex on the provided JSON String to find the 'link' tag.
*
* @param jsonResponse
* The JSON response from Imgur.
* @return
* The link to the image.
*/
private String getLink(String jsonResponse)
{
Pattern pattern = Pattern.compile("link\":\"(.*?)\"");
Matcher matcher = pattern.matcher(jsonResponse);
matcher.find();
return matcher.group().replace("link\":\"", "").replace("\"", "").replace("\\/", "/");
}
/**
* Uses Regex on the provided JSON String to find the 'id' tag.
*
* @param jsonResponse
* The JSON response from Imgur.
* @return
* The id of the image or album.
*/
private String getId(String jsonResponse)
{
Pattern pattern = Pattern.compile("id\":\"(.*?)\"");
Matcher matcher = pattern.matcher(jsonResponse);
matcher.find();
return matcher.group().replace("id\":\"", "").replace("\"", "");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment