【发布时间】:2012-05-31 13:07:13
【问题描述】:
我正在使用this tutorial 序列化 C# 字典。
C# 字典被序列化为字符串。
@Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(ElementDivIDs)) 就像一个魅力。这是我得到的输出:
var jsonString = {"9":["ele9-tabs-attr9","ele9-tabs-attr48"],"10":["ele10-tabs-attr10"],"11":["ele11-tabs-attr11"],"12":["ele12-tabs-attr12","ele12-tabs-attr49"],"13":["ele13-tabs-attr13"],"14":["ele14-tabs-attr14"]}
我想将其转换为 Javascript 关联数组。 但是对 jquery.parseJSON 的调用返回 NULL。
var dictionaryOfOtherDivs = jQuery.parseJSON( jsonString );
dictionaryOfOtherDivs 在此之后为空。
这是我的代码:
<script type="text/javascript">
$(document).ready(function () {
var jsonString = @Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(ElementDivIDs))
console.log(jsonString);
var dictionaryOfOtherDivs = jQuery.parseJSON( jsonString );
for(var dictKey in dictionaryOfOtherDivs)
{
console.log("key = " + dictKey + ", value = " + dictionaryOfOtherDivs[dictKey]);
}
//Do some more things
});
</script>
【问题讨论】:
标签: javascript jquery json serialization