拼凑json的实例
一,拼凑 json 串 并传到后台
function writeToJson(num){ var i = 1; var jsonData = "["; for(i=1;i<=num;i++){ var dataname = $("input[name='dataname"+i+"']").val(); var datacontent = $("input[name='datacontent"+i+"']").val(); var noOpenInterface = $("input[name='noOpenInterface"+i+"']").val(); var isopen=$("input:radio[name='isopen"+i+"']:checked").val(); if(i == num ){ jsonData += "{'dataname':'"+dataname+"','datacontent':'"+datacontent+"','isopen':'"+isopen+"','noOpenInterface':'"+noOpenInterface+"'}"; }else{ jsonData += "{'dataname':'"+dataname+"','datacontent':'"+datacontent+"','isopen':'"+isopen+"','noOpenInterface':'"+noOpenInterface+"'},"; } } jsonData += "]" ; //alert("--------"+jsonData); return jsonData ; }