Hi @Nevitha Ravi,
I tried the code sample you provided, but its throwing following error-
error CS1061: 'JsonOptions' does not contain a definition for 'SerializerSettings' and no accessible extension method 'SerializerSettings' accepting a first argument of type 'JsonOptions' could be found (are you missing a using directive or an assembly reference?)
I have also added the following package with the mentioned version-
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
can you please help??
PamTheOK, We checked our shared sample at our end and it works as expected. We suspect that you are using the provided solution on the core sample project which uses the .net core version greater than 2. You can resolve the problem by installing the NuGet package “Microsoft.AspNetCore.Mvc.NewtonsoftJson” and use the solution as shown in the below code snippet. Refer to the below link for more details.
https://stackoverflow.com/questions/55666826/where-did-imvcbuilder-addjsonoptions-go-in-net-core-3-0
[Program.cs]
builder.Services.AddMvc().AddNewtonsoftJson(x => { x.SerializerSettings.ContractResolver = new DefaultContractResolver(); }) .AddNewtonsoftJson(x => x.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat) .AddNewtonsoftJson(x => x.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local); |
Hi Venkatesh,
The above code worked for me, thanks for it.
But one weird thing that I noticed is after using the code snippet in my code, I am getting all the API responses in Pascal Case, where as earlier it was Camel Case. and due to this change my data from other API is not loading on the page despite of getting data from API.
attaching screenshots link for reference-
https://drive.google.com/drive/folders/1X9qDjWyVANydoT2S7RNaydwPH0mQZYUL?usp=share_link
PamTheOK, You can resolve the problem by removing the highlighted line in the snip.