如何在Java中解析或分割URL地址? [英] How to parse or split URL Address in Java?

查看:1383
本文介绍了如何在Java中解析或分割URL地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



https://graph.facebook.com/me/home?limit=25&since=1374196005



我可以得到(或拆分)参数(避免硬编码)?



像这样



https /// graph.facebook.com /// 我/ home /// {limit = 25,sincse = 1374196005}

解决方案

使用Android的 Uri 类。 http://developer.android.com/reference/android/net/Uri.html

  Uri uri = Uri.parse(https://graph.facebook.com/me/home?limit=25&since = 1374196005\" ); 
String protocol = uri.getScheme();
String server = uri.getAuthority();
String path = uri.getPath();
设置< String> args = uri.getQueryParameterNames();
String limit = uri.getQueryParameter(limit);


If I have url address.

https://graph.facebook.com/me/home?limit=25&since=1374196005

Can I get(or split) parameters (avoiding hard coding)?

Like this

https /// graph.facebook.com /// me/home /// {limit=25, sincse=1374196005}

解决方案

Use Android's Uri class. http://developer.android.com/reference/android/net/Uri.html

Uri uri = Uri.parse("https://graph.facebook.com/me/home?limit=25&since=1374196005");
String protocol = uri.getScheme();
String server = uri.getAuthority();
String path = uri.getPath();
Set<String> args = uri.getQueryParameterNames();
String limit = uri.getQueryParameter("limit");

这篇关于如何在Java中解析或分割URL地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆