I would like to be able to say, this attribute has to be first in the serialized json. Our json structure includes href to resource, and we would like to have it be a 1st attribute in json. Is it possible?

有帮助吗?

解决方案

Use the DataContract and DataMember attributes. They will work for both JSON and XML. The JSON properties might not work for all SerivceStack versions but I've confrimed it works with v4.

[System.Runtime.Serialization.DataContract]
public class Team : IReturn<Team>
{
    [System.Runtime.Serialization.DataMember(Order = 3)]
    public int Id { get; set; }

    [System.Runtime.Serialization.DataMember(Order = 2)]
    public string Name { get; set; }

    [System.Runtime.Serialization.DataMember(Order = 1)]
    public DateTime CreatedDate { get; set; }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top