【发布时间】:2018-05-26 19:51:37
【问题描述】:
var data2 = results.FormData["model2"];
下面是来自 angular json data2 的示例输出,用于在 asp.net MVC web api 中进行转换
{
"0":{"RowStamp":2,"Department":"Billing and Collection"},
"1":{"RowStamp":7,"Department":"Business Development"},
"2":{"RowStamp":10,"Department":"Construction Management/Design"}
}
我有模型课
public class DeptModel
{
public int RowStamp { get; set; }
public string Department { get; set; }
}
var dictionary = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<DeptModel>(data2);
调试时出错
Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List
有人可以帮我反序列化这个模型吗?如果提供示例代码会更好。提前致谢
【问题讨论】:
-
你有代表类似结构的类吗?您是否尝试将其用作操作方法参数?请分享相关代码
-
你需要一个模型类同时包含属性
RowStamp&Department,然后使用JavaScriptSerializer.Deserialize方法或类似的方法来反序列化JSON对象。 -
你为什么不用
Json.net又名Newtonsoft.Json? -
对我来说看起来像是一个类列表.....用 Newtonsoft 很容易
-
使用反序列化
)> ...抱歉我的平板电脑不好,无法轻松输入
标签: c# asp.net angularjs asp.net-mvc