【问题标题】:Simplest way to make and parse json request android [duplicate]制作和解析json请求android的最简单方法[重复]
【发布时间】:2014-08-04 22:35:17
【问题描述】:

我需要使用 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 中执行此操作

【问题讨论】:

  • 阅读本文以了解如何在 android 上发出 HTTP 请求:stackoverflow.com/a/3506039/1239966
  • @ShivamVerma 无论如何这对我没有帮助。我不想发出http请求,我想发出json请求然后解析它
  • 您是否已经保存了 json 字符串?你能成功找回吗?

标签: java android json web android-json


【解决方案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));

【讨论】:

    猜你喜欢
    • 2016-03-06
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    • 2015-01-19
    • 1970-01-01
    • 2017-06-30
    相关资源
    最近更新 更多