Convert a class to a Json Object in c#

I have a class DraftForm :

public class DraftForm 
{
    public string Json { get; set; }
    public System.DateTime CreatedDate { get; set; }
    public string DraftNumber { get; set; }
    public string DraftName{ get; set; }
}

In this method I want to return a Json of the DraftForm class :

public Object GetAllDraftDossier()
{
    var draftDossiers = _context.DraftForms
        .Where(x=> x.DraftName== "Repairer")
        .ToList();
    var json = Newtonsoft.Json.JsonConvert.SerializeObject(
        draftDossiers, 
        new JsonSerializerSettings { 
            ContractResolver = new CamelCasePropertyNamesContractResolver()
        }
    );
    return json;
}

In postman it returns a string and not a json ! Can anyone help me ?



Read more here: https://stackoverflow.com/questions/66320014/convert-a-class-to-a-json-object-in-c-sharp

Content Attribution

This content was originally published by hiba nebli at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: