Unexpected output using reduce to create json

 ̄綄美尐妖づ 提交于 2021-02-11 13:41:48

问题


I'm working with apps script. I have an array of objects 'sendableRows' that I would like to turn to json and email. an object looks like:

[{Phone Number=14444444444, Eagerness=High, Index=4816.0, completed=, Lot Size=0.74, Power or water=, campaign=, absoluteRow=84.0}]

my code:

const json = sendableRows.reduce(row => JSON.stringify(row), "")

Logger.log(json);

MailApp.sendEmail({
to: 'xxxx@gmail.com',
subject: todayString,
htmlBody: json
});

unfortunately 'json' is being output as:

[20-07-26 20:07:55:244 EDT] "\"\\\"\\\\\\\"\\\\\\\"\\\"\""

What am I doing wrong?


回答1:


Try

const json = JSON.stringify(sendableRows);


来源:https://stackoverflow.com/questions/63107142/unexpected-output-using-reduce-to-create-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!