吕展辉

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

function StringBuffer(){  
    this.strings = new Array;  
}  
 
StringBuffer.prototype.append=function(str){  
    this.strings.push(str); //追加指定元素  
};  
 
StringBuffer.prototype.toString = function(){  
    return this.strings.join(""); //向数组之间的元素插入指定字符串(此处为空字符串),并返回。  
};  
StringBuffer.prototype.append=function(str){  
    this.strings.push(str); //追加指定元素  
};

之后可以使用StringBuffer:

var strBuffer = new StringBuffer();
        strBuffer.append("{\"gshts\":\'{");
        $.each(vos.gshts,function(index,gsht2){
            //JSON.stringify(gsht);
            if(parseInt(index) != parseInt(0)){
                //alert(index);
                strBuffer.append(',');
            }
            strBuffer.append( "\"gsht\":" + JSON.stringify(gsht2) + "");
        });
        strBuffer.append("}\'}");

posted on 2014-03-16 11:20  吕展辉  阅读(298)  评论(0编辑  收藏  举报