/** 转义JSON字符串 */ function zyJSON(strJson) { return strJson.replace(/\\/g, "\\\\").replace(/\"/g, "\\\""); } var objJson = {"type":0,"id":"20190816-1011","name":"20190816-1011","mobile":""}; objJson.name = '远思\\软件'; console.log(zyJSON(JSON.stringify(objJson)));