Return camelCased JSON from Web API

前端 未结 6 1073
攒了一身酷
攒了一身酷 2020-12-31 11:42

I\'m trying to return camel cased JSON from an ASP.Net Web API 2 controller. I created a new web application with just the ASP.Net MVC and Web API bits in it. I hijacked t

6条回答
  •  别那么骄傲
    2020-12-31 12:03

    You need to use OK() instead of Json() in your action methods.

    // GET api/values
    public IHttpActionResult Get()
    {
        var thing = new Thing
        {
            Id = 123,
            FirstName = "Brian",
            ISBN = "ABC213", 
            ReleaseDate = DateTime.Now,
            Tags = new string[] { "A", "B", "C", "D"}
        };
    
        // Use 'Ok()' instead of 'Json()'
        return Ok(thing);
    }
    

提交回复
热议问题