如果这是我的json对象 - 如何在我的处理程序中访问该对象?

时间:2011-10-24 19:04:06

标签: jquery asp.net json httphandler

  var handler = "HttpHandlers/UpdateAdditionalCoverageDetailsHandler.ashx";
                var coverages = { PersonID: personId, DetCode: "", Reimbursement: "", Deductible: "", MaximumPerAnnum: "", MaximumPerVisit: "", MaximumPerVisits: "", SvcCode: "" };
                var maximums = { PersonID: personId, DetCode: ["ACUPUN", "PODIAT", "OSTEOP"], MaximumPerAnnum: "" };
                var obj = { Coverages: coverages, CoverageCombinedMaximums: maximums };

                var objJson = JSON.stringify(obj);
                var data = '{ "items":' + objJson + '}';

                callHandler(handler, data, saveSuccessful, failure);

和我调用处理程序的函数:

 function callHandler(handler, obj, onSuccess, onFail) {

                $.ajax({
                    type: "POST",
                    url: handler,
                    data: obj, // obj,
                    //contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: onSuccess,
                    fail: onFail

                });

            }

和我的处理程序中的方法:

 public void ProcessRequest (HttpContext context) {
        bool isSuccessful = true;

        var items = context.Request.Params["items"];

        if (isSuccessful)
        {

            JavaScriptSerializer ser = new JavaScriptSerializer();
            Dictionary<string,object> dict = ser.Deserialize<Dictionary<string, object>>(items);

        }
        else
        {
            SendErrorMessage(context);
            return;
        } 
    }

0 个答案:

没有答案