c#serialization / deserialization和反斜杠

时间:2017-09-16 17:54:29

标签: c# json serialization

我正在尝试序列化/反序列化我的数据。但是在结果的开头和结尾添加了"。并且反斜杠的标志比插入中间的标志更糟糕。

例如,如https://jsonformatter.curiousconcept.com/所示,结果为:

enter image description here

我尝试将反斜杠转换为其他符号。

我的模特:

public partial class oyunlar
{        
    public oyunlar()
    {

    }
    public Nullable<int> oyun_id { get; set; }
    public string oyun_adi { get; set; }
    public Nullable<System.DateTime> oyun_tarihi { get; set; }
    public int salon_id { get; set; }
    public int tur_id { get; set; }
    public string oyun_aciklama { get; set; }
    public string oyun_suresi { get; set; }
    public byte[] oyun_foto { get; set; }


    public virtual oyun_turu oyun_turu { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<oyuncular> oyunculars { get; set; }
    public virtual salonlar salonlar { get; set; }
}

我的控制器:

 public async Task<ActionResult> Index()
    {
        var jason = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
        jason.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
        JsonSerializerSettings jsSettings = new JsonSerializerSettings();
        jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
        jsSettings.PreserveReferencesHandling = PreserveReferencesHandling.All;
        jsSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        var oyunlars = db.oyunlars.Include(o => o.oyun_turu).Include(o => o.salonlar);
        var converted = JsonConvert.SerializeObject(oyunlars, jsSettings);
        return Json(converted, JsonRequestBehavior.AllowGet);
    }

请注意,我特别需要使用ReferenceLoopHandlingPreserveReferencesHandling进行序列化。我该如何解决?

0 个答案:

没有答案