有没有办法使用JSON.NET指定序列化JSON对象中字段的顺序?
It would be sufficient to specify that a single field always appear first.
有没有办法使用JSON.NET指定序列化JSON对象中字段的顺序?
It would be sufficient to specify that a single field always appear first.
支持的方法是对要设置顺序的类属性使用JsonProperty
属性.更多信息,请阅读JsonPropertyAttribute order documentation.
Pass the JsonProperty
an Order
value and the serializer will take care of the rest.
[JsonProperty(Order = 1)]
This is very similar to the
DataMember(Order = 1)
在这System.Runtime.Serialization
天里.
Here is an important note from @kevin-babcock
... setting the order to 1 will only work if you set an order greater than 1 on all other properties. By default any property without an Order setting will be given an order of -1. So you must either give all serialized properties and order, or set your first item to -2