카테고리 없음

[C#] Customize json class property

ibelieveinme 2023. 11. 9. 16:44
728x90

Json 데이터를 Class 객체로 만들 때,

Json Key 값에 특수문자가 들어있는 경우가 있다.

 

JsonProperty 의 PropertyName 으로 Property 이름을 커스터마이징 할 수 있다.

[JsonProperty(PropertyName = "Feedback_IM&SR")]
string _feedback_imsr { get; set; }

https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/customize-properties?pivots=dotnet-8-0

 

How to customize property names and values with System.Text.Json - .NET

Learn how to customize property names and values when serializing with System.Text.Json in .NET.

learn.microsoft.com

https://stackoverflow.com/questions/38719368/special-characters-in-property-name

 

Special characters in property name

In my Application a webservice will return a json { "UserDetails": [ { "UserId": "57", "EmailId": "prasant@xyz.com", "UserName": "Prasant", "TimezoneMins"...

stackoverflow.com

 

728x90