Sahadev Dodiya February 2016

.net Web API Json Property attribute not working when serilize using JsonConvert.serilizeObject

Json libarary to convert data to json

this is my main method which return two list one with property list List and another is List

  public static Tuple<List<RoomDayBook>, List<string>> DayBookRowData(DateTime StartDate, DateTime EndDate, int SupplierId, bool wantSubRoom)
        {
            DataSet dsDayBook = FillDayBookData(StartDate, EndDate, SupplierId);

           ............................ 
           ............................

                lstDayBook.Add(objDayBook);
            }
            return new Tuple<List<RoomDayBook>, List<string>>(lstDayBook, Guests);
        }

In this RoomDayBook class in which i use JsonProperty which give jsonproperty name in json serilization in stand of property name

public class RoomDayBook
{
    [JsonProperty(PropertyName = "RC")]
    public string RoomCode { get; set; }
    [JsonProperty(PropertyName = "RN")]
    public string RoomName { get; set; }
    [JsonProperty(PropertyName = "HS")]
    public bool HasSubRoom { get; set; }
    [JsonProperty(PropertyName = "RD")]
    public List<RoomDetail> RoomDetails { get; set; }
    [JsonProperty(PropertyName = "SRs", NullValueHandling = NullValueHandling.Ignore)]
    public List<RoomDayBook> SubRooms { get; set; }
}

it's woking perfectly in normal aspx webmethods but not working in web api please help me find me reason behind it

Answers


Sahadev Dodiya February 2016

I found problem in different version of Newton.json library different between class library and Web API Project that's it not convert it in proper format

Post Status

Asked in February 2016
Viewed 2,893 times
Voted 13
Answered 1 times

Search




Leave an answer