문제

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