I am using below code to convert my model class to JSON data
[DataContract]
public class EventList
{
[DataMember(Name = "success")]
public int success;
[DataMember(Name = "result")]
public List<CalendarEvent> Result;
}
[DataContract]
public class CalendarEvent
{
[DataMember(Name = "id")]
public int Id {get;set; }
[DataMember(Name = "title")]
public string Title { get; set; }
[DataMember(Name = "url")]
public string Url { get; set; }
[DataMember(Name = "class")]
public string EventClass { get; set; }//event-warning event-success event-special event-important event-inverse
[DataMember(Name = "start")]
public long StartTime { get; set; }
[DataMember(Name = "end")]
public long EndTime { get; set; }
}
EventList model = new EventList();
//Load data
MemoryStream stream1 = new MemoryStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(EventList));
ser.WriteObject(stream1, model);
stream1.Position = 0;
StreamReader sr = new StreamReader(stream1);
string json_data= sr.ReadToEnd();
The generated JSON looks like this when i am opening from browser
//"{\"result\":[{\"class\":\"event-warning\",\"
So how can i get rid of forward slashes . The question is not about serialize to JSON and showing custom properties, but about removing slashes from response
Returning model directly instead of parsed JSON is a way , but in my case i have a property name "class" inside CalendarEvent class which i cant modify , since the plugin [ https://github.com/Serhioromano/bootstrap-calendar ] i am using demanding the structure like this So i have to use JSON Serializationa anyway So how can i get rid of this forward slash and unwanted quotes issue?