我有一个类似这样的URL:
http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394
如何获取章节和文章参数的值?
我的URL中在章节参数的值中包含了'&'。
在Android中,您可以使用Uri类来实现此目的;https://developer.android.com/reference/android/net/Uri.html
Uri uri = Uri.parse("http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394");
String server = uri.getAuthority();
String path = uri.getPath();
String protocol = uri.getScheme();
Set<String> args = uri.getQueryParameterNames();
然后你甚至可以这样从查询参数中获取特定的元素;
String chapter = uri.getQueryParameter("chapter"); //will return "V-Maths-Addition "
Uri.parse().getQueryParameter()
- Blackbelt&
进行URL编码。据我所知,应该是%26或类似的内容。 - Fildor