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) + "]";