我打電話給我使用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