纯脚本组装Json格式字符串

     var answerStr = "[";
        for (var i in answer) {
            var data = $("input[name=QuestionItem_" + answer[i] + "]:checked").attr("data");
            answerStr += ('{"id":"' + answer[i] + '" ,"answer":"' + $("input[name=QuestionItem_" + answer[i] + "]:checked").attr("id") + '","score":"' + data + '"},');

        }
        answerStr = answerStr.substring(0, answerStr.length - 1) + "]";

 

posted @ 2015-11-30 10:48  创可贴Y  阅读(377)  评论(0编辑  收藏  举报