我有一个像http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394
如何从android中的url获取参数?
请有人帮我找到章节和帖子的参数值?
我的网址在chapter参数的值中包含'&'。
我有一个像http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394
如何从android中的url获取参数?
请有人帮我找到章节和帖子的参数值?
我的网址在chapter参数的值中包含'&'。
你可以在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 "
chapter =“V-Maths-Addition” –
我的预期输出是“V-Maths-Addition&Subtraction” –
请参阅上面的注释。您需要转义/ url编码'&'。它不能在价值中。你从哪里得到该网址。你有控制其建设? – Fildor
如果您的参数有空格或其他空格字符,则使用POST方法发送数据。 –
在java或android框架中解析URI的类很少,到目前为止您尝试过了什么? – Selvin
'Uri.parse()。getQueryParameter()' – Blackbelt