Json格式和String格式转换函数

[code]
function _dataTransform(){
var _this = this;
_this.jsonToString=function(obj){

switch(typeof(obj)){
case ‘string’:
return ‘”‘ + obj.replace(/([“\\])/g, ‘\\$1’) + ‘”‘;
case ‘boolean’:
if(obj)
return ‘true’;
else
return ‘false’;
case ‘array’:
return ‘[‘ + obj.map(_this.jsonToString).join(‘,’) + ‘]’;
case ‘object’:
// //if(obj instanceof Array){
// if(obj.constructor.toString().match(/^\s*function Array\(\)/)){
// var strArr = [];
// var len = obj.length;
// for(var i=0; i

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>