我有这个简单的课程:
[DataContract]
class MyClass
{
[DataMember]
public string Name { get; set; }
[DataMember]
public int Value { get; set; }
[DataMember]
public int Amount { get; set; }
}
我正在将它序列化:
MyClass test1 = new MyClass { Name= "Product1", Value = 230, Amount = 22 };
MyClass test2 = new MyClass { Name= "Product2", Value = 110, Amount = 10 };
List<MyClass> MyList = new List<MyClass>() { test1, test2 };
string output = JsonConvert.SerializeObject(MyList);
Console.Write(output);
与文档不同,这会产生一行。我想在JSON
wiki上生成一种格式。
[{&#34;名称&#34;:&#34;产品1&#34;&#34;值&#34;:230,&#34;量&#34;:22},{&#34 ;名称&#34;:&#34;产品2&#34;&#34;值&#34;:110,&#34;上午'mount&#34; 10}]
对于这样的事情:
[
{
"Name":"Product1",
"Value":230,
"Amount":22
},
{"Name":"Product2"
,"Value":110,
"Amount":10
}
]