json与url的转换

有一个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的转换)