Code:
protected stringFormaturlencode (stringURL) { stringresult =string. Empty; if(URL.) IndexOf ("?") <0)returnresult; stringDomain=url. Split ('?')[0]. ToString (); stringparas = URL. Split ('?')[1]. ToString (); string[] Para = paras. Split ('&'); StringBuilder Strbuilder=NewStringBuilder (); Strbuilder.append (Domain+"?"); foreach(varPainchpara) { stringName = Pa. Split ('=')[0]; stringValue = Pa. Split ('=')[1]; if(value.) Contains ('[') &&value. Contains (']') &&value. Contains ('{') &&value. Contains ('}')) { stringContent = value. Substring (1, value. Length-2); List<string> list =Newlist<string>(); //You cannot use commas here, because object attributes are also commas if(content. Contains ("},{") ) {list= Regex.Split (Content,"},{"). ToList (); list[0] = list[0]. Substring (1, list[0]. Length-1); intindex = list. Count ()-1; List[index]= List[index]. Substring (0, List[index]. Length-1); } Else{list. ADD (content. Substring (1, content. Length-2)); } strbuilder.append (Name+"=["); foreach(varLinchlist) { //the L object here is to get rid of the property set of {,}Strbuilder.append ("{"); string[] jsons = L.split (','); foreach(varJinchjsons) { //when Val is a link that contains a colon inside, it will have less data string[] Vals = J.split (':'); stringKey = J.split (':')[0]; stringval = J.split (':')[1]; //To troubleshoot http://www.baidu.com if(Vals. Length >2) {Val= J.substring (key. length+1, J.length-key. length-1); } strbuilder.append (Key+":"+ Httputility.urlencode (val) +","); } Strbuilder= Strbuilder.remove (Strbuilder.length-1,1); Strbuilder.append ("}"); Strbuilder.append (","); } Strbuilder= Strbuilder.remove (Strbuilder.length-1,1); Strbuilder.append ("]&"); } Else{strbuilder.append (name+"="+ Httputility.urlencode (value) +"&"); }} Strbuilder= Strbuilder.remove (Strbuilder.length-1,1); returnstrbuilder.tostring (); }
Link:
http//www.baidu.com?blabel=&buid=&createTime=2015-01-16 10:02:42&customeraddress=&customercomment =&customermobile=&customername=&orderlist=[{"AgentName": "Ctrip", "Itemamount": 2, "itemId": 3022641, " Itemimgurl ":", "ItemName": "The same process test resource", "Itemorderdetail": "", "Itemorderdetailwap": "", "Itemordertime": "2014-12-10" , "Itemprice": 10000, "Itemurl": "http://piao.ctrip.com/dest/t12.html" ," Itemurlwap ":"http://m.ctrip.com/webapp/ticket/dest/t12.html"}] &ordername=&partnerid=ctrip&payway= Test Products Online Payment &srcorderid=1800000009&status=104&totalamount=11000&key=baidulvyou_wangyonghui
Encrypt unencrypted parameters in a link with JSON object