我有一个这样的网址:
http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394
如何获取章节和帖子的参数值?
我的网址在章节参数的值中包含“&”。
最佳答案
您可以使用 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 "
关于java - 如何从 Android 中的 URL 获取参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40466217/