-1

I need to use a JSON api, but don't know how to do so. All the tutorials i have found are about parsing json from a file.

I need to make a request like this: http://expandurl.appspot.com/expand?url=http%3A%2F%2Ft.co%2FgLP0Ucg

and then it will return this

{"status": "OK", "end_url": "http://www.systemcomic.com/2011/06/27/the-system-506-office-forecast/", "redirects": 3, "urls": ["http://t.co/gLP0Ucg", "http://www.notquitewrong.com/rosscottinc/2011/06/27/the-system-506-office-forecast/", "http://www.systemcomic.com//2011/06/27/the-system-506-office-forecast/", "http://www.systemcomic.com/2011/06/27/the-system-506-office-forecast/"], "start_url": "http://t.co/gLP0Ucg"}

I just need the end_url string. How would i do this? I am also going to be doing this in a ASyncTask

Finley Smith
  • 1,599
  • 2
  • 11
  • 15

1 Answers1

1

For getting the JSON you need to extract it using http request and after you get the response you then parse it to get the end_url.

try this to parse end_url:

final Pattern pattern = Pattern.compile("\"end_url\": \"(.+?)\",");
final Matcher matcher = pattern.matcher(You_json_string);
matcher.find();
Log.d("end_url" , matcher.group(1));
Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63