locked
Newtonsoft Json returning lowercase RRS feed

  • Question

  • User1984354752 posted

    Hi there:

    I installed Newtonsoft.Json in my ASP.NET Core in my web development project. Although my models names start with Uppercase letter, the Json string return them  lowercase so I can't render them in the jqgrid. I guess that  I have to instruct the application  in the start class to override this behavior but I'm exhausting searching for how to do it. 

    Start up class 

    public void ConfigureServices(IServiceCollection services)
    {

    services.AddMvc().AddNewtonsoftJson(options => options.SerializerSettings ???????? 

    }

    Sunday, July 19, 2020 1:55 PM

Answers

  • User711641945 posted

    Hi 9peculiar,

    For asp.net core 3.x,it should be like below:

    services.AddControllers()
    .AddNewtonsoftJson(opt =>
    opt.SerializerSettings.ContractResolver = new DefaultContractResolver());

    For asp.net core 2.x,it should be like below:

    services.AddMvc()
    .AddJsonOptions(opt => opt.SerializerSettings.ContractResolver = new DefaultContractResolver());

    Best Regards,

    Rena

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 20, 2020 6:39 AM
  • User-474980206 posted

    jqGrid does not care the case of the columns, though most examples would be lowercase. By convention json data is camelcased, which is why asp.net core switched to this as a default. 

    I would suggest just fixing the jqGrid config and following the conventions. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 20, 2020 3:40 PM

All replies

  • User475983607 posted

    The solution depends on the version of Core and project type.  The standard ASP.NET docs cover JSON format fundamentals.

    https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/formatting?view=aspnetcore-3.1

    Sunday, July 19, 2020 2:19 PM
  • User711641945 posted

    Hi 9peculiar,

    For asp.net core 3.x,it should be like below:

    services.AddControllers()
    .AddNewtonsoftJson(opt =>
    opt.SerializerSettings.ContractResolver = new DefaultContractResolver());

    For asp.net core 2.x,it should be like below:

    services.AddMvc()
    .AddJsonOptions(opt => opt.SerializerSettings.ContractResolver = new DefaultContractResolver());

    Best Regards,

    Rena

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 20, 2020 6:39 AM
  • User-474980206 posted

    jqGrid does not care the case of the columns, though most examples would be lowercase. By convention json data is camelcased, which is why asp.net core switched to this as a default. 

    I would suggest just fixing the jqGrid config and following the conventions. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 20, 2020 3:40 PM
  • User1984354752 posted

    Thanks Rena Ni....I followed your advice and works 

    Thursday, July 23, 2020 11:25 AM