C#字典到Javascript [英] C# Dictionary to Javascript
本文介绍了C#字典到Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中有这本词典.
I have this Dictionary in C#.
Dictionary<string, string[]>
我序列化了字符串,现在我想获取javascript中的所有键,并显示带有该键的警报消息,并将值加载到var StringArrayItems
我在jscript中有这个
var dictionary = eval((" + dict +)");
现在我想要这样的东西
I serialized the string and now I want to get all the keys in javascript and show an alert message with the key and also load value into a var StringArrayItems
I have this in jscript
var dictionary = eval( "(" + dict + ")" );
And now I want something like this
for(var s in dictionary)
{
alert(s);
var strings = s.value;
}
推荐答案
为什么不使用AJAX(XMLHttpRequest)并直接从Javascript中的服务器获取字符串?我不太确定我们是否可以根据需要遍历Javascript中的Dictionary项. AJAX方法将非常简单.试试吧!
AFAIK,这是通过词典"方式最想要的东西: JavaScript词典 [ ^ ]-示例使用.NET代码,但很容易理解.
Why not use AJAX (XMLHttpRequest) and get the string formed directly from server in your Javascript? I am not too sure that we can traverse through a Dictionary item in Javascript as you want to. AJAX approach would be simple and easy. Try it!
AFAIK, This is the closest thing to what you want via Dictionary way: Javascript Dictionary[^] - sample uses .NET code but is quite simple to understand.
这篇关于C#字典到Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文