0
我想創建一個動態的請求模型,我可以添加自己的自定義字段。只是閱讀了很多關於泛型的知識,並想知道是否可以這樣做。如何初始化mvc中的類對象中的字典
public class Request
{
public string Action { get; set; }
public List<DynamicQueries> Queries { get; set; }
}
public class DynamicQueries {
public Dictionary<string,string> Query { get; set; }
}
爲了做類似
var ReqObj = new Request() {
Action = "GetUsers",
Queries = new List<DynamicQueries> {
new DynamicQueries {
Query = new Dictionary<string,string> {
{ "Query1", "True" },
{ "Query2", "false" }
}
}
}
它打印出
{
"Action": "GetUsers",
"Queries": [
{
"Query": {
"Query1": "True",
"Query2": "false"
}
}
]
}
我如何得到它的輸出這個呢?
謝謝,這有幫助,我已經更新了這個問題。你能幫我嗎? – archytect 2014-10-17 15:08:37