A
A
Alexander Nikulshin2020-08-18 23:20:59
ASP.NET
Alexander Nikulshin, 2020-08-18 23:20:59

How to capitalize JSON field names in ASP Net core?

I have a class:

class Step
    {
        public int idStep { get; set; }
        public string StepName { get; set; }
        public int GlassCount { get; set; }
        public bool isCutting { get; set; }
        public bool isShpt { get; set; }
    }


When I issue it to the API:
public List<Step> GetSteps()
        {
            return new StepList().GetSteps();
        }
//public List<Step> GetSteps()

This results in a JSON array like this:
[
    {
        "idStep": 23,
        "stepName": "Раскрой",
        "glassCount": 0,
        "isCutting": true,
        "isShpt": false
    },
    {
        "idStep": 24,
        "stepName": "Кромщик",
        "glassCount": 0,
        "isCutting": false,
        "isShpt": false
    }
]


Then, when deserializing in the client application, through the System.Text.JSON class, I have to write the fields of the class into which this data is converted with a small letter.
public class Step
    {
        public int idStep { get; set; }
        public string stepName { get; set; }
        public int glassCount { get; set; }
        public bool isCutting { get; set; }
        public bool isShpt { get; set; }
    }


Tell me, how can I display json data so that it is capitalized?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2020-08-18
@xasya89

Well, you can define a JsonNamingPolicy for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question