在JSON结果中转义双引号

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

我有一组代码,我已经完成了错误处理。我希望结果是{"ErrorMessage": Server is down}然而我继续得到{"ErrorMessage":"Server is down"}的结果。

这是我的代码:

catch (Exception e)
        {
            var result = "Server is down";
            return Ok(new { ErrorMessage = result });
        }

我尝试使用'@'和'\'字符,但它不起作用。我如何逃避这些额外的双引号?有人请帮帮我。非常感谢你提前。

c# json
1个回答
1
投票

我决定保留结果,因为{"ErrorMessage":"Server is down"}是显示JSON输出的正确方法。正如@dbc所解释的那样,这是一个有效的JSON对象,其属性名为ErrorMessage,其值为string Server is down

© www.soinside.com 2019 - 2024. All rights reserved.