gpt4 book ai didi

javascript - JSON 字符串化格式错误

转载 作者:行者123 更新时间:2023-11-28 07:29:49 24 4
gpt4 key购买 nike

var email_recept=document.getElementsByClassName("email");
var counting_email_recept=email_recept.length;
var array_mail=[];
var myJSON=[];
for(var i=0;i<counting_email_recept;i++)
{
array_mail[i]=email_recept[i].value;
myJSON[i]=JSON.stringify({ email: array_mail[i] });
}

console.log(myJSON);
result :
["{"email":""}", "{"email":""}"]
i want to make like this : [{"email":""}, {"email":""}]

最佳答案

尝试使用此代码:

var email_recept=document.getElementsByClassName("email");
var counting_email_recept=email_recept.length;
var array_mail=[];
var myJSON=new array();
for(var i=0;i<counting_email_recept;i++)
{
array_mail[i]=email_recept[i].value;
myjson[i] = { email: array_mail[i] };
}
myJSON = JSON.stringify(myJSON);
console.log(myJSON);

你会得到想要的输出!

关于javascript - JSON 字符串化格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29247786/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com