JS对象序列化成json数据和json数据转化为JS对象
JS对象序列化成json数据:
[代码] [JS]代码
01 |
function Serialize(obj){?????
|
02 |
???? switch (obj.constructor){?????
|
03 |
???????? case Object:?????
|
04 |
???????????? var str = "{" ;?????
|
05 |
???????????? for ( var o in obj){?????
|
06 |
???????????????? str += o + ":" + Serialize(obj[o]) + "," ;?????
|
08 |
???????????? if (str. substr (str.length-1) == "," )?????
|
09 |
???????????????? str = str. substr (0,str.length -1);?????
|
10 |
????????????? return str + "}" ;?????
|
11 |
????????????? break ;?????
|
12 |
????????? case Array:?????????????????
|
13 |
????????????? var str = "[" ;?????
|
14 |
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
|