esc*_*ist 3 javascript jquery serialization json
我正在使用本教程来序列化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"]}
Run Code Online (Sandbox Code Playgroud)
我想将其转换为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>
Run Code Online (Sandbox Code Playgroud)