1

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:

enter image description here

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?

dbc
  • 104,963
  • 20
  • 228
  • 340
  • Looks like a duplicate of [JSON.NET Parser *seems* to be double serializing my objects](https://stackoverflow.com/q/25559179) and also [Strings sent through Web API's gets wrapped in quotes](https://stackoverflow.com/q/33681978/3744182). – dbc Sep 16 '17 at 17:59
  • If you have to use Json.NET to return an `ActionResult`, see [Using JSON.NET to return ActionResult](https://stackoverflow.com/q/23348262). If you need to return an `ActionResult` using ReferenceLoopHandling, that answer should explain how to do it. – dbc Sep 16 '17 at 18:05
  • oh thank you i will tried. @dbc – devdevdevelop Sep 16 '17 at 18:12

0 Answers0