我如何解析Android中的URL

时间:2017-05-06 19:06:37

标签: android

我的应用程序我应该解析URl,我应该从 ID

获得 id 号码
  

http://example.com/cat/detail/proc?id=147&_prof=W6IYDQZ2F2YOVBC78RUA

如何解析此网址并获取ID和教授?

3 个答案:

答案 0 :(得分:1)

使用getQueryParameter()

 Uri uri=Uri.parse("http://example.com/cat/detail/proc?id=147&_prof=W6IYDQZ2F2YOVBC78RUA");
String id = uri.getQueryParameter("id");
String _prof = uri.getQueryParameter("_prof");

答案 1 :(得分:0)

Uri uri = Uri.parse("http://example.com/cat/detail/proc?id=147&_prof=W6IYDQZ2F2YOVBC78RUA");
String id = uri.getQueryParameter("id");

答案 2 :(得分:0)

试试这个

List<NameValuePair> parse = URLEncodedUtils.parse(URI.create("http://example.com/cat/detail/proc?id=147&_prof=W6IYDQZ2F2YOVBC78RUA"), "UTF-8");
        for (NameValuePair pair : parse) {
            System.out.println("!!!!!!!!!! " + pair.getName() + " = " + pair.getValue());
    }