我需要使用JSON api,但不知道如何操作。我找到的所有教程都是关于从文件中解析json。
我需要提出这样的请求:http://expandurl.appspot.com/expand?url=http%3A%2F%2Ft.co%2FgLP0Ucg
然后它将返回此
{"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"}
我只需要end_url字符串。我该怎么办?我也将在ASyncTask中执行此操作
答案 0 :(得分:1)
要获取JSON
,您需要使用http请求提取它,然后在获得响应后再解析它以获取end_url
。
尝试此操作来解析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));