سؤال

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