//例如下面这个json串,中间的 表示换行 var str = "{' retmsg':'success ', ' trans_date':' 20170906'}"; console.log(str); //"{' retmsg':'success ', //' trans_date':' 20170906'}" //去掉空格 str = str.replace(/ +/g,""); console.log(str); //"{'retmsg':'success', //'trans_date':'20170906'}" //去掉回车换行 str = str.replace(/[ ]/g,""); console.log(str); //"{'retmsg':'success','trans_date':'20170906'}"