簡體   English   中英

為什么ASP.net WebApi在JSON輸出中轉義日期?

[英]Why is ASP.net WebApi escaping dates in JSON output?

我目前正在研究WebApi轉義日期的項目。 例如。

{"Date":"11\/05\/2016"}

而且一定是這個

{"Date":"11/05/2016"}

該模型。

public class XModel
{
        public string Date { get; set; }
}

控制器。

public class DatesController : ApiController
{
    [HttpGet]
    [Route("api/dates/{take:int?}")]
    [ResponseType(typeof(XModel))]
    public XModel GetDates(int take = 0)
    {
        return new XModel()
        {
            Date = "11/05/2016"
        };
    }
}

看起來該項目正在轉義JSON響應中的每個斜杠(“ /”)。 有人知道解決方案嗎?

非常感謝,喬迪

我想您已經為您的Web API使用了json序列化程序,因此請嘗試以下方式:

public class DatesController : ApiController
{
    [HttpGet]
    [Route("api/dates/{take:int?}")]
    public IHttpActionResult GetDates(int take = 0)
    {
        return Ok(new
        {
            Date = "11/05/2016"
        });
    }
}

希望能幫助到你!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM