1
 var questionOptionArray=[{"questionCode":"1111111177","optionCode":"1111111147"},                 {"questionCode":"1111111103","optionCode":"test"},{"questionCode":"1111111104","optionCode":"1111111212"},{"questionCode":"1111111105","optionCode":"1111111215"},{"questionCode":"1111111106","optionCode":"test2"}]
  var jsonobj = JSON.stringify(questionOptionArray);
            alert(jsonobj);
            $.ajax({
                type: "POST",
                url: "Services/Quiz.asmx/InsertUserQuiz",
                data: JSON.stringify({ questionOptionArray: questionOptionArray }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) { alert(data); },
                failure: OnError
            });

        }

在 quiz.asmx 我的代码:

public class Quiz : System.Web.Services.WebService
    {
        public class optionDetail
        {
            string questionCode { get; set; }
            string optionCode { get; set; }
        }

        [WebMethod]
        public string InsertUserQuiz(List<optionDetail> questionOptionArray)
        {
            var count = questionOptionArray.Count();
            return "1";
        }
    }

我得到了有五个计数的 questionOptionArray 的空值。,如何在 Web 服务中获取 questionCode、optionCode 的值,以便我可以将它们插入数据库。

4

1 回答 1

0

由于您的方法需要一个optionDetail尝试发送这些对象数组的列表。

 var questionOptionArray=[{"questionCode":"1111111177","optionCode":"1111111147"},{"questionCode":"1111111103","optionCode":"test"},{"questionCode":"1111111104","optionCode":"1111111212"},{"questionCode":"1111111105","optionCode":"1111111215"},{"questionCode":"1111111106","optionCode":"test2"}];
  var jsonobj = JSON.stringify(questionOptionArray);
            alert(jsonobj);
            $.ajax({
                type: "POST",
                url: "Services/Quiz.asmx/InsertUserQuiz",
                data: jsonobj,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) { alert(data); },
                failure: OnError
            });

        }
于 2012-12-08T06:07:54.253 回答