【问题标题】:Json deserialization is not supportted不支持 Json 反序列化
【发布时间】:2014-01-23 19:13:09
【问题描述】:

我在反序列化 .NET MVC5 中的数组时遇到问题,我们将不胜感激。

JsonList psl = (new JavaScriptSerializer()).Deserialize<JsonList>(id);

我的对象

[Serializable]
public class JsonList
{
    public object[] id { get; set; }
    public List<children> children { get; set; }
}
[Serializable]
public class children
{
    public List<object> id { get; set; }
}

Json 数组

 "[
   {\"id\":20,\"children\":[]},{\"id\":21,\"children\":[{\"id\":23},
        {\"id\":22},   {\"id\":24},
   {\"id\":26}]},{\"id\":27,\"children\":[{\"id\":56},{\"id\":57},
        {\"id\":51},{\"id\":50},
   {\"id\":55},{\"id\":52},{\"id\":65},{\"id\":53}]},
        {\"id\":28,\"children\":[{\"id\":29},
   {\"id\":30},{\"id\":32},{\"id\":79}]},
       {\"id\":33,\"children\":[{\"id\":34},{\"id\":35},
   {\"id\":39}]},{\"id\":40,\"children\":[{\"id\":41},{\"id\":42},
           {\"id\":43},{\"id\":44},
   {\"id\":75}]},{\"id\":45,\"children\":[{\"id\":47},
           {\"id\":82},{\"id\":49}]}
]"

Jquery 可排序

var UINestable=function(){
var updateOutput=function(e){
    var list = e.length ? e : $(e.target), output = list.data('output');
    var dataid = window.JSON.stringify(list.nestable('serialize'));
    if (window.JSON) {
        alert(dataid);
        $.ajax(
            {
                type: 'POST',
                url: '/Admin/Menuler/MenuSiralama',
                data: "{id:'" + dataid + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                success: function(result) {
                },
                error: function() {
                }
            }
        );
    }       
    else{console.log('JSON browser support required for this demo.');}
};
return{init:function(){
      $('#nestable_list_1').nestable({group:2})
               .on('change',updateOutput);}};
}();

【问题讨论】:

  • 你在使用 json.net 库吗?

标签: jquery json jquery-ui-sortable asp.net-mvc-5


【解决方案1】:

试试这个:

[Serializable]
public class JsonList
{
    public object[] id { get; set; }
    public children children { get; set; }
}

根据您尝试发布的 JSON 数据示例,您无需将 children 属性视为 List。

children 属性应该是子类类型(您将其声明为子类列表),或者支持 JSON 结构中的子类集合。

【讨论】:

    猜你喜欢
    • 2014-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-07
    • 2021-02-26
    • 1970-01-01
    • 2019-02-16
    • 1970-01-01
    相关资源
    最近更新 更多