解决方案 »

  1.   

     data: {"strJson": json},
      

  2.   

    这里的data是jQuery.ajax的参数,他是json格式对象"strJson":json   
    "strJson"为RoleFunc.aspx/Convert的参数名称,这里的json为字符串就可以了
      

  3.   

    感谢楼上的大大
    感谢昨天对我的回复,这个。我已经尝试过.但是它提示
    Invalid JSON primitive: strJson
      

  4.   

    尝试使用text post..还是无法进行postT_T继续找原因。。顺便求助
      

  5.   

    inference as following01.$.ajax({  
    02.    type: "POST",  
    03.    url: "WebService.asmx/WebMethodName",  
    04.    data: <span style="color: rgb(255, 102, 102);">"</span>{'fname':'dave', 'lname':'ward'}<span style="color: rgb(255, 0, 0);">"</span>,  
    05.    contentType: "application/json; charset=utf-8",  
    06.    dataType: "json"  
    07.});  
      

  6.   


            var strJson = { Users: [{ Id: 1, Name: "Ahoo1" }, { Id: 2, Name: "Ahoo2"}] }
            var url="@Url.Action("DesJson")";
            $.ajax({
                url: url,
                dataType: "json",
                data: { json: JSON.stringify(strJson.Users) },//将数组对象持久化为string
                success: function (data) {
                    alert(data);
                },
                error: function (data) {
                    alert(data);
                }
            });        public JsonResult DesJson(string json)
            {
                IList<DataDemo> datas = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<DataDemo>>(json);//使用Newtonsoft 反序列化
                return Json(datas, JsonRequestBehavior.AllowGet);
            }
      

  7.   


    遗漏了 实体类[DataDemo]        public class DataDemo
            {
                public int Id { get; set; }
                public string Name { get; set; }
            }
      

  8.   

    data: { json: JSON.stringify(strJson.Users) }这个部分要是没有进行转换那么提交参数将是这样
      

  9.   

        var _json = "'{\"abc\":\"123\"}'";
        //var json = { "menu": [{ "Role_ID": "2", "Customer_ID": "155", "Brands": "Chloe", "Country_ID": "96" }, { "Role_ID": "-1", "Customer_ID": "497", "Brands": "Chloe", "Country_ID": "96"}] };
        $.ajax({
            url: "test_ajax.aspx/Convert",
            type: "POST",
            contentType: "application/json",
            data: '{ "strJson":'+  _json +'}',
            success: function (result) {
                alert(result.d);
            },
            error: function () {
                alert("error");
            }
        });
      

  10.   

    感谢楼上的大大
    感谢昨天对我的回复,这个。我已经尝试过.但是它提示
    Invalid JSON primitive: strJson这个的原因应该是你写了contentType: "application/json",需要返回一个json格式的字符串应该是这样吧~~
      

  11.   

        var json = "'{ \"menu\":[{\"Role_ID\":\"2\",\"Customer_ID\":\"155\",\"Brands\":\"Chloe;\",\"Country_ID\":\"96;\"},{\"Role_ID\":\"-1\",\"Customer_ID\":\"497\",\"Brands\":\"Chloe;\",\"Country_ID\":\"96;\"}]}'";
        $.ajax({
            url: "test_ajax.aspx/Convert",
            type: "POST",
            contentType: "application/json",
            data: '{ "strJson":' + json + '}',
            success: function (result) {
                alert(result.d);
            },
            error: function () {
                alert("error");
            }
        });
      

  12.   

    感谢楼上的大大
    感谢昨天对我的回复,这个。我已经尝试过.但是它提示
    Invalid JSON primitive: strJson这个的原因应该是你写了contentType: "application/json",需要返回一个json格式的字符串应该是这样吧~~

    这个是提交的格式,是你请求的格式问题,直接把这个contentType整个干掉,它自己有默认的,data直接传{"strJson":json},里面的冒号打不打是一样的。然后后台接收(string strJson)
      

  13.   

    下面是解析的代码:public class CustomerRole
    {
        public string Role_ID { get; set; }
        public string Customer_ID { get; set; }
        public string Brands { get; set; }
        public string Country_ID { get; set; }
    }
    public class CustomerShell
    {
        public CustomerRole[] menu;
    }
    var json = @"{""menu"":[{""Role_ID"":""2"",""Customer_ID"":""155"",""Brands"":""Chloe;"",""Country_ID"":""96;""},{""Role_ID"":""-1"",""Customer_ID"":""497"",""Brands"":""Chloe;"",""Country_ID"":""96;""}]}";
    CustomerShell obj = (CustomerShell)new DataContractJsonSerializer(typeof(CustomerShell)).ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(json)));