我使用下面的代码将我的模型类转换为JSON数据
[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();
当我从浏览器
打开时,生成的JSON看起来像这样//"{\"result\":[{\"class\":\"event-warning\",\"
那我怎么能摆脱正斜杠呢?问题不是关于序列化到JSON并显示自定义属性,而是关于从响应中删除斜杠
直接返回模型而不是解析JSON是一种方式,但在我的情况下,我有一个属性名称&#34; class&#34;在我无法修改的CalendarEvent类中,因为我使用的插件[https://github.com/Serhioromano/bootstrap-calendar]要求像这样的结构 所以我还是要使用JSON Serializationa 那么我怎样才能摆脱这种正斜线和不需要的报价问题呢?