jquery 拼接Json格式 然后输出,要可以正确运行的,请问怎么写
"persons":[{"sex":"男","name":"李小名"},{"sex":"女","name":"小徐"},{"sex":"男","name":"小明"},{...
"persons":[ {"sex":"男","name":"李小名"}, { "sex" : "女" , "name" :"小徐"}, { "sex" : "男" , "name" :"小明"}, { "sex" : "女" ,"name" :"小张"}, { " sex ":"男", "name" :"小李"}, {"sex":"男", "name" :"小孙"}, {"sex":"男", "name" :"小赵"}] 输出这样的格式,
展开
展开全部
你这写的不就挺好吗,还要怎么写?
var data = {"persons":[ {"sex":"男","name":"李小名"}, { "sex" : "女" , "name" :"小徐"}, { "sex" : "男" , "name" :"小明"}, { "sex" : "女" ,"name" :"小张"}, { " sex ":"男", "name" :"小李"}, {"sex":"男", "name" :"小孙"}, {"sex":"男", "name" :"小赵"}]};
alert(data);
要这样?打印出来?
var data = {"persons":[ {"sex":"男","name":"李小名"}, { "sex" : "女" , "name" :"小徐"}, { "sex" : "男" , "name" :"小明"}, { "sex" : "女" ,"name" :"小张"}, { " sex ":"男", "name" :"小李"}, {"sex":"男", "name" :"小孙"}, {"sex":"男", "name" :"小赵"}]};
alert(data);
要这样?打印出来?
追问
我需要的是拼接JSON格式的JQuery代码
追答
这个js拼接吧,和jquery没关系
回家了,先给你个思路吧
var data = ‘{"persons":[ ’;
for(var i=0,i<10,i++){
data += '{"sex":"男","name":"李小名"},';
}
data += ']}';
alert(data);
for里面你I自己换成循环输出,我写的静态的,回家了,再有问题晚上说
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询