I am trying to serialize/deserialize my data. But "
is added at the beginning and ending of the result. And backslash signs worse than it are inserted in the middle.
For example, as shown in in https://jsonformatter.curiousconcept.com/, the result is:
I tried to convert backslash to other sign.
My model:
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; }
}
My controller:
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);
}
Note that I specifically need to serialize using ReferenceLoopHandling
and PreserveReferencesHandling
. How can I solve it?