美文网首页
json与url的转换

json与url的转换

作者: qhaobaba | 来源:发表于2017-06-25 00:28 被阅读0次

有一个url  file:///android_asset/hrfile/html/review/reveiw_cc.html?id=1111&sessionid=ssssssssssssssss&domain=http://10.0.100.110:8080/jeesite/a

//获取 参数 param

vargetParam = {

href :function(){

varhref  ="file:///android_asset/hrfile/html/review/reveiw_cc.html?id=1111&sessionid=ssssssssssssssss&domain=http://10.0.100.110:8080/jeesite/a/";

varparams = href.split("?")[1];

varparamArr = params.split('&');

varres = {};

for(vari = 0;i

varstr = paramArr[i].split('=');

res[str[0]]=str[1];

}

returnres;

},

jsessionid :function(){

varobj = getParam.href();

returnobj.sessionid

} ,

id:function(){

varobj = getParam.href();

returnobj.id

},

domain :function(){

varobj = getParam.href();

returnobj.domain

}

}

var parseParam = function(param,key){varparamStr="";if(paraminstanceofString||paraminstanceofNumber||paraminstanceofBoolean){paramStr+="&"+key+"="+encodeURIComponent(param);}else{$.each(param,function(i){vark=key==null?i : key+(paraminstanceofArray?"["+i+"]":"."+i);paramStr+='&'+parseParam(this,k);});}returnparamStr.substr(1);};varobj={"name":'tom',"class":{"className":'class1'},"classMates":[{"name":'lily'}]};

console.log(parseParam(obj));

//name=tom&class.className=class1&classMates[0].name=lily

console.log(parseParam(obj,'stu'));

//stu.name=tom&stu.class.className=class1&stu.classMates[0].name=lily

相关文章

网友评论

      本文标题:json与url的转换

      本文链接:https://www.haomeiwen.com/subject/ikgccxtx.html