如何为单个操作方法使用 Pascal Case 制作 JSON 输出密钥?

问题描述 投票:0回答:0

我正在尝试从单个控制器操作返回 JSON 输出(不想将其设置为全局),就像这样(PascalCase):

{
    "AuthenticationResult":{
            "AccessToken":
            "ExpiresIn":
            "TokenType":
            "RefreshToken":
            "IdToken":
    }
}

DTO类:

public class AuthResponse
    {
        public AuthenticationResult authenticationResult { get; set; }


    }

    public class AuthenticationResult
    {
        [JsonProperty("AccessToken")]
        public string AccessToken { get; set; }
        public int ExpiresIn { get; set; }
        public string TokenType { get; set; }
        public string RefreshToken { get; set; }
        public string IdToken { get; set; }
    }

控制器方法:

public async Task<IHttpActionResult> GetAuthenticationToken(string Guid = null)
{
    try
        {
            
                
                var AuthResponse = await _Business.GetAuthenticationTokenAsync(Guid, null);

                return Ok(AuthResponse, this);
            
        }

        catch (Exception ex)
        {
            return BadRequest(ex.Message);
        }
 

}
c# asp.net json
© www.soinside.com 2019 - 2024. All rights reserved.