Javascript debugging class JavaScript Object array string converter JavaScript debug class

Source: Internet
Author: User

 Function object2string (OBJ) <br/>{< br/> var val, output = ""; <br/> If (OBJ) <br/>{< br/> output + = "{"; <br/> for (var I in OBJ) <br/>{< br/> val = OBJ [I]; <br/> switch (typeof Val) <br/>{< br/> case ("object "): If (Val [0]) {output + = I + ":" + array2string (VAL) + "," ;}else {output + = I + ": "+ object2string (VAL) +", ";}break; <br/> case (" string "): Output + = I +": '"+ encodeuri (VAL) + "',"; break; <br/> default: Output + = I + ":" + Val + ","; <br/>}< br/> output = output. substring (0, output. length-1) + "}"; <br/>}< br/> return Unescape (output); <br/>}< br/> function array2string (array) <br/> {<br/> var output = ""; <br/> If (array) <br/> {<br/> output + = "["; <br/> for (var I in array) <br/>{< br/> val = array [I]; <br/> switch (typeof Val) <br/>{< br/> case ("object"): <br/> If (Val [0]) <br/> {output + = array2string (VAL) + "," ;}< br/> else <br/> {output + = object2string (VAL) + "," ;}< br/> break; <br/> case ("string"): <br/> output + = "'" + encodeuri (VAL) + "',"; <br/> break; <br/> default: <br/> output + = Val + ","; <br/>}< br/> output = output. substring (0, output. length-1) + "]"; <br/>}< br/> return Unescape (output); <br/>}< br/> function string2object (string) <br/>{< br/> eval ("Var result =" + decodeuri (string); return result; <br/>}< br/> function string2array (string) <br/>{< br/> eval ("Var result =" + decodeuri (string); return result; <br/>}

 

Test code:

 

Function coworker (name, age, Dept) {This. name = Name; this. age = age; this. department = dept ;}< br/> var OBJ ={}; <br/> obj. name = "DETP one"; <br/> obj. action = "sale"; <br/> var Kevin = new coworker ("Kevin", 28, OBJ); <br/> var objstr = object2string (Kevin ); <br/> alert (objstr); <br/>

 

Used materials:

 

VaR STR = "http://hi.baidu.com/bbjjss2008l? Country = China & name = JZ "; <br/> var urlstr = escape (STR); <br/> document. write ("escape method encryption: <br/>" + urlstr + "<br/> after decryption, the URL string is: <br/> "+ Unescape (STR); <br/> urlstr = encodeuri (STR); <br/> document. write ("<br/> encodeuri: Method encryption: <br/>" + urlstr + "<br/> the decrypted URL string is: <br/> "+ decodeuri (STR); <br/> urlstr = encodeuricomponent (STR); <br/> document. write ("<br/> encodeuricomponent: Method encryption: <br/> "+ urlstr +" <br/> the decrypted URL string is: <br/> "+ decodeuricomponent (STR); <br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.