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.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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
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.
Member
21 Points
99 Posts
Newtonsoft Json returning lowercase
Jul 19, 2020 01:55 PM|9peculiar|LINK
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 ????????
}
All-Star
52971 Points
23573 Posts
Re: Newtonsoft Json returning lowercase
Jul 19, 2020 02:19 PM|mgebhard|LINK
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
Contributor
2690 Points
874 Posts
Re: Newtonsoft Json returning lowercase
Jul 20, 2020 06:39 AM|Rena Ni|LINK
Hi 9peculiar,
For asp.net core 3.x,it should be like below:
For asp.net core 2.x,it should be like below:
Best Regards,
Rena
All-Star
58124 Points
15641 Posts
Re: Newtonsoft Json returning lowercase
Jul 20, 2020 03:40 PM|bruce (sqlwork.com)|LINK
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.
Member
21 Points
99 Posts
Re: Newtonsoft Json returning lowercase
Jul 23, 2020 11:25 AM|9peculiar|LINK
Thanks Rena Ni....I followed your advice and works