1

I have an Action in my Web api controller That returns an instance of SampleClass. when SampleClass has Fields, the result of Action is this: {}

and when i replace my Fields with Properties the result is afilled Json as expected. Can any one explain Why this is Happening?

2 Answers 2

1

JSON Serialization only works on Properties by default, that is one of the main reasons to choose between using Fields or Properties

As a C# developer I assume you've read Why Properties Matter (by the illustrious Jon Skeet)

Sign up to request clarification or add additional context in comments.

1 Comment

I have been working c# in Unity3d for a time.now in asp.net i face some basic challenges
1

For response serialization your application is probably configured to use System.Text.Json, which by default ignores fields as described here: link

However you are able to make fields serializable by adding corresponding attribute: another link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.