• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Jison Spec

The James Room

Nervous Newbie
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.
 
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!
 
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?
 
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.
 
Bisically:

public IActionResult GetCompanies()
{
return Json(this._service.GetCompanies());
}

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 that you have.

Code:
    services.AddMvc().AddJsonOptions(o =>
    {
        o.SerializerSettings.ContractResolver = new DefaultContractResolver()
        {
            NamingStrategy = new SnakeCaseNamingStrategy()
        };
    });
 
Last edited: 15:02
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()
        };
    });

Amizing!
 

Advertisers

Back
Top