- Joined
- Sep 25, 2018
- Messages
- 12
- Likes received
- 1
- Thanks received
- 1
Any of you keyboard kids tell me why the returned JISON from a web service captilises and adds underscores to variable names?
So CompanyCode in my server code becomes companY_CODE in the JISON.
I Feel like I need a crystal ball.
Nope, but I can recommend you post this in the "Technical" section - or suffer the consequences, you clueless twat!
Nope, but I can recommend you post this in the "Technical" section - or suffer the consequences, you clueless twat!
Any of you keyboard kids tell me why the returned JISON from a web service captilises and adds underscores to variable names?
So CompanyCode in my server code becomes companY_CODE in the JISON.
I Feel like I need a crystal ball.
So I dont know why a web service would expect CompanyCode and return Company_code. I don't think there is consistent approach to json property names but I would expect the input and output to be the same.
What does the web service documentation say?
There isn't any. I wrote it.
Perhaps this is the way that .net API serialises Jison.
Show me the codez.
Bisically:
public IActionResult GetCompanies()
{
return Json(this._service.GetCompanies());
}
services.AddMvc().AddJsonOptions(o =>
{
o.SerializerSettings.ContractResolver = new DefaultContractResolver()
{
NamingStrategy = new SnakeCaseNamingStrategy()
};
});
If you are using ASP.NET Core MVC and you have this in the Startup.cs then it will convert your property names to company_name. Just remove it and it should default to camel case. I don't think its the default, so you may have added it? Don't know without seeing the code what you have.
Code:services.AddMvc().AddJsonOptions(o => { o.SerializerSettings.ContractResolver = new DefaultContractResolver() { NamingStrategy = new SnakeCaseNamingStrategy() }; });