Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个清单:
var list = new List<int>{1,2,3};
如何将其添加到匿名对象中,使对象看起来像:
{ list : [1,2,3] }
var obj = new { list = list };
obj现在是一个匿名对象,具有名为listtype的属性List<int>。
obj
list
List<int>
通过创建匿名对象:
var anon = new { list }
我假设你希望它看起来像这样:
您正在谈论 JSON 序列化的输出,一旦您序列化,它就会看起来像。