【发布时间】:2011-05-09 13:19:55
【问题描述】:
我构建了一个导航树并使用这个函数将结构保存在一个数组中
function parseTree(html) {
var nodes = [];
html.parent().children("div").each(function () {
var subtree = $(this).children("div");
var item = $(this).find(">span");
if (subtree.size() > 0)
nodes.push([item.attr("data-pId"), item.attr("data-id"), parseTree(subtree)]);
else
nodes.push(item.attr("data-pId"), item.attr("data-id"));
});
return nodes;
}
然后我序列化数据
var tree = $.toJSON(parseTree($("#MyTree").children("div")));
获取这个数组
[
["881150024","881150024",
[
"994441819","881150024",
"214494418","881150024"
]
],
["-256163399","-256163399",
[
"977082012","-256163399",
"-492694206","-256163399",
[
"1706814966","-256163399",
["-26481618","-256163399"]
]
]
]
]
并通过ajax发送
$.ajax({
url: "Editor/SerializeTree",
type: "POST",
data: { tree: tree },
success: function (result) {
alert("OK");
}
});
问题:如何在 C# 中使用 JavaScriptSerializer 反序列化这个 JSON?
【问题讨论】:
标签: c# json serialization deserialization