C#字典相当于在JavaScript中 [英] C# Dictionary equivalent in JavaScript

查看:348
本文介绍了C#字典相当于在JavaScript中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时存在任何JavaScript中的C#字典。我有在angularjs一个应用程序从一个MVC的Web API请求数据,一旦它得到,这让一些修改。因此,该数据是对象的数组,这是存储在MVC的Web API作为对象的词典,但我将其转换为它传递通过量网络之前上市。

Is there exist any kind of c# dictionary in JavaScript. I've got an app in angularjs that requests data from an MVC Web Api and once it gets, it makes some changes to it. So the data is an array of objects, which is stored in the MVC Web Api as a Dictionary of objects, but I convert it to list before passing it throug network.

如果我直接转换字典以JSON我得到的是这样的:

If I convert the Dictionary directly to JSon I get something like:

array = [ {Id:"1", {Id:"1", Name:"Kevin Shields"}}, 
          {Id:"2", {Id:"2", Name:"Natasha Romanoff"}}
        ];



嘛对象是稍微复杂一点,但你现在已经有了一个主意。问题是,这种格式是更难操作与(我有字母键或IDS)。那么,有没有相当于一个字典?这是很简单的事东西一样:

Well the objects are a little more complex, but you've got now an idea. The problem is that this format is even harder to operate with (I've got alphabetical keys or ids). So is there any equivalent to a dictionary? It's quite simple to do thing like:

Object o = dictionary["1"];



原来是这样,提前感谢。

So that's it, thank in advance.

推荐答案

您有两种选择真的,虽然两者本质上做同样的事情,它可能是值得一读多一点的这里,如果你想定制的解决方案,谈论关联数组(字典):

You have two options really, although both essentially do the same thing, it may be worth reading a bit more here, which talks about associative arrays (dictionaries), if you wish to tailor the solution:

var dictionary = new Array(); 
dictionary['key'] = 'value'



或者

Alternatively:

var dict = []; 

dict.push({
    key:   'key',
    value: 'value'
});

这篇关于C#字典相当于在JavaScript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆