我正在研究 ASP.NET MVC4.0。
我的字符串从视图中是这样发布的:-
[{"name":"AddressNumber","value":"1"},{"name":"OrganizationProd","value":""},{"name":"ClientId","value":""},{"name":"ProductId","value":""},{"name":"TaxId1","value":""},{"name":"TaxId2","value":""},{"name":"LaborID","value":"0"}]
下面是我的控制器的操作方法,它正在接收输入:-
[AllowAnonymous]
[HttpPost]
public ActionResult UpdateProducts(string ModelString){
}
下面是我正在执行的字符串(在 ModelString 变量中):-
[{"name":"AddressNumber","value":"1"},{"name":"OrganizationProd","value":""},{"name":"ClientId","value":""},{"name":"ProductId","value":""},{"name":"TaxId1","value":""},{"name":"TaxId2","value":""},{"name":"LaborID","value":"0"}]
之后我像这样反序列化字符串:-
var sear = new JavaScriptSerializer();
var dictDynamic = sear.Deserialize<dynamic>(ModelString);
我正在 dictDynamic 变量中获取动态数组。现在我想通过其名称获取属性,而不是通过从 dictDynamic 对象进行索引。
目前我通过这样的索引来获取属性: -
dictDynamic[0]["value"]
dictDynamic[1]["value"]
但我想按这样的属性名称解析它:-
dictDynamic["Name"]["value"]
dictDynamic["Description"]["value"]
谁能帮我解决这个问题?