Create Json dynamically in c#
问题 I need to create a Json object dynamically by looping through columns. so declaring an empty json object then add elements to it dynamically. eg: List<String> columns = new List<String>{"FirstName","LastName"}; var jsonObj = new {}; for(Int32 i=0;i<columns.Count();i++) jsonObj[col[i]]="Json" + i; And the final json object should be like this: jsonObj={FirstName="Json0", LastName="Json1"}; 回答1: [TestFixture] public class DynamicJson { [Test] public void Test() { dynamic flexible = new