webapi – remove web api json string only

by default web api return is xml only. even return json string, but it is still embedded inside an xml file.

for example:

1
2
3
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
[{"Id":1,"Name":"Glenn Block"},{"Id":2,"Name":"Dan Roth"}]
</string>

in WebApiConfig.cs:

1
  config.Formatters.Remove(config.Formatters.XmlFormatter);

then it will be json string only.

Another sub topic is json object in C#.

add reference in visual studio that json serialization.
using System.Web.Script.Serialization;

System.Web.Script.Serialization is inside System.Web.Extensions.

This entry was posted in Uncategorized. Bookmark the permalink.