我打电话给我使用MVC4 ApiController编写的Web API。
它返回一个Dictionary<int, int>
这样的:
return Request.CreateResponse<Dictionary<int, int>>(HttpStatusCode.OK, histogram);
这将返回以下JSON对象:
{
"$type": "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[System.Int32, mscorlib]], mscorlib",
"4": 113,
"0": 716,
"1": 443,
"2": 226,
"3": 123,
"5": 4,
"26": 3
}
该对象具有属性$type
引用它对应于.NET类型。我不希望这个被发送给我的客户。
我该如何摆脱$type
属性?
http://stackoverflow.com/questions/1636885/remove-item-到jsson前in-dictionary-based-value- –
不要返回字典,它只针对.NET,对于任何不是.NET客户端的api消费者都是毫无意义的。 – Maess
我的API调用只是将一些键/值对作为JSON对象返回。我知道一个字典是特定于.NET的;这恰好是我的控制器中键/值对的表现方式。 '$ type'属性不在我要返回的字典中。 MVC似乎是自己添加属性。 – jcarpenter2