0

我通过 ajax 将数据发布到 aspx 页面,现在我不知道如何阅读它。我只需要获取通过 JSON 传递的字符串并将它们分配给某些变量并操作 .aspx 文件中的变量。我该怎么做呢?

这是jQuery:

var ceSaveDatea = {};
    ceSaveDatea.one = requestNumber;
    ceSaveDatea.two = itemTypeID;
    ceSaveDatea.three = servicesRequired;
    ceSaveDatea.four = otherComments;
    ceSaveDatea.five = suggestedReplacements;
    ceSaveDatea.six = internalTestingRequired;
    ceSaveDatea.seven = externalTestingRequired;
    ceSaveDatea.eight = ceGeneralComments;

    /*
    var url = "../ajaxURLs/ComponentEngineering.aspx?requestNumber=" + requestNumber + "&itemTypeID=" + itemTypeID + "&servicesRequired=" + servicesRequired + "&otherComments=" + otherComments + "&suggestedReplacements=" + suggestedReplacements + "&internalTestingRequired=" + internalTestingRequired + "&externalTestingRequired=" + externalTestingRequired + "&ceGeneralComments=" + ceGeneralComments;
    var encodedURL = EncodeURL(url);
    */

    $.ajax({
        type: "POST",
        url: "/ajaxURLs/ComponentEngineering.aspx",
        data: JSON.stringify(ceSaveDatea),  
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function (data) {
            alert(data);
            if (data != '')
                $('#checkboxContainerDiv').html(data);
        },
        error: function(msg) {
        alert('error');
        }
    });

然后我只需要获取这些信息并在 ComponentEngineer.aspx 页面上进行转换。它不是网络服务。

谢谢!

4

2 回答 2

1

如果你想在 C# 代码中处理 JSON,我强烈建议你去探索JSON.NET

于 2012-09-17T23:26:45.027 回答
0

以下代码应该可以满足您的需求:

        JavaScriptSerializer serializer = new JavaScriptSerializer();
        Dictionary<object, object> jsonLookup = ((Dictionary<object, object>)serializer.Deserialize<Dictionary<object, object>>(jsonSource));

传递给 Deserialize 方法的“jsonSource”是您的 JSON 字符串。

先决条件是:

  • 包括对 .NET 程序集的引用:System.Web.Extensions
  • 在类文件的顶部包含一个 using 语句: using System.Web.Script.Serialization;
于 2012-09-18T03:29:42.713 回答