/**
* Created by myc on 2015/12/9.
*/
import android.text.TextUtils; import java.util.HashMap;
import java.util.Map; public class URLUtil { /**
* 去掉url中的路径,留下请求参数部分
* @param strURL url地址
* @return url请求参数部分
*/
private static String truncateUrlPage(String strURL)
{
if(TextUtils.isEmpty(strURL)){
return null;
}
String strAllParam=null;
strURL=strURL.trim().toLowerCase();
String[] arrSplit = strURL.split("[?]"); //有参数
if(arrSplit.length>1)
{
if(arrSplit[1]!=null)
{
strAllParam=arrSplit[1];
}
} return strAllParam;
}
/**
* 解析出url参数中的键值对
* @param URL url地址
* @return url请求参数部分
*/
public static Map<String, String> getRequestParamMap(String URL)
{
if(TextUtils.isEmpty(URL)){
return null;
} String strUrlParam=truncateUrlPage(URL);//得到参数
if(TextUtils.isEmpty(strUrlParam))
{
return null;
} Map<String, String> mapRequest = new HashMap<String, String>();
//每个键值为一组
String[] arrSplit=strUrlParam.split("[&]");
for(String strSplit:arrSplit)
{
String[] arrSplitEqual= strSplit.split("[=]"); //解析出键值
if(arrSplitEqual.length>1)
{
if(!TextUtils.isEmpty(arrSplitEqual[1]))
{
mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);//正确解析
}else{
mapRequest.put(arrSplitEqual[0], "");//无value
}
}
}
return mapRequest;
}
}

URL网址参数解析类的更多相关文章

  1. gin的url查询参数解析

    gin作为go语言最知名的网络库,在这里我简要介绍一下url的查询参数解析.主要是这里面存在一些需要注意的地方.这里,直接给出代码,和运行结果,在必要的地方进行分析. 代码1: type Struct ...

  2. url查询参数解析

    url查询参数解析 1.获取url的各部分值 举例http://i.cnblogs.com/EditPosts.aspx?opt=1 1.window.location.href(设置或获取整个 UR ...

  3. Node基础:url查询参数解析之querystring

    模块概述 在nodejs中,提供了querystring这个模块,用来做url查询参数的解析,使用非常简单. 模块总共有四个方法,绝大部分时,我们只会用到 .parse(). .stringify() ...

  4. 将url的参数解析为Json数据

    代码如下: <!DOCTYPE> <html lang="en"> <head> </head> <body> < ...

  5. js截取URL网址参数

    将本页代码复制粘贴到html页面,打开即可. <!DOCTYPE html> <html lang="en"> <head> <meta ...

  6. url的参数解析成key-value

    function urlController(url) { var _url = url.split("?")[1]; if(!_url){ return {}; } var wi ...

  7. 把url的参数解析出来

    https://zhidao.baidu.com/question/455797151306205205.html

  8. Js把URL中的参数解析为一个对象

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title&g ...

  9. javascript:将URL的参数列表解析为一个对象

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

随机推荐

  1. 字典:dict.c/dict.h

    Redis 源码分析(1):字典和哈希表(dict.c 和 dict.h)http://huangz.iteye.com/blog/1455808两个点:字典结构的运作流程哈希表的渐进式 rehash ...

  2. JavaScriptSerializer 日期处理 JSON.Net

    [WebMethod(Description = "取得所有人员 自带json")] [SoapHeader("key")] [ScriptMethod(Res ...

  3. sgu176 有源汇上下界最小流

    题意:有一堆点和边,1起点,n终点,某些边有可能必须满流,要求满足条件的最小流 解法:按原图建边,满流的即上下界都是容量,但是这样按有源汇上下界可行流求出来的可能不是最小流,那么我们需要开始建边的时候 ...

  4. 51nod 1428 贪心

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:13107 ...

  5. HANA 存储过程

    You can develop secure procedures using SQLScript in SAP HANA by observing the following recommendat ...

  6. Memcache mutex设计模式

    Memcache mutex设计模式 转自:https://timyang.net/programming/memcache-mutex/ 场景 Mutex主要用于有大量并发访问并存在cache过期的 ...

  7. mapreduce-实现单表关联

    //map类 package hadoop3; import java.io.IOException; import org.apache.hadoop.io.LongWritable;import ...

  8. 门禁 IC卡 ID 卡 RFID 手环 NFC 银行卡 手机模拟门禁

    门禁 IC卡 ID 卡 RFID 手环 NFC 银行卡 手机模拟门禁 原因 最近给公司换了一个门禁. 旧的门禁按键面板已经破了. 不支持我的手环. 按了密码后竟然要按 #. 相关信息 查了资料记录一下 ...

  9. 《Orange’s 一个操作系统的实现》1.搭建操作系统开发环境

    书中给出了两种环境:windows和linux,平台选择根据自己喜好.本人这里选择ubuntu10.04+virtualbox作为开发平台. 1.下载.安装VirtualBox     http:// ...

  10. HIVE-利用ow_number() OVER(PARTITION BY)函数介绍求TOP-K

    http://blog.csdn.net/631799/article/details/7419797 第一句话: select row_number() over (partition by mon ...