2
我送JSON:在WCF設置JSON對象名稱REST
[
{
"Description": "A kud ces bolje",
"ItemID": 1,
"Name": "Banane",
"NewPrice": 91.99,
"OldPrice": 161.99,
"SaleEnds": "9/1/2013",
"SaleStarts": "9/1/2012"
},
{
"Description": "Rastu na stablu",
"ItemID": 2,
"Name": "Kruske",
"NewPrice": 93.99,
"OldPrice": 117.99,
"SaleEnds": "9/1/2013",
"SaleStarts": "9/1/2012"
},
]
但我希望有一個名稱,這樣它看起來像
"Some_Name":[
{
"Description": "A kud ces bolje",
"ItemID": 1,
"Name": "Banane",
"NewPrice": 91.99,
"OldPrice": 161.99,
"SaleEnds": "9/1/2013",
"SaleStarts": "9/1/2012"
},
{
"Description": "Rastu na stablu",
"ItemID": 2,
"Name": "Kruske",
"NewPrice": 93.99,
"OldPrice": 117.99,
"SaleEnds": "9/1/2013",
"SaleStarts": "9/1/2012"
},
]
我回到List<Item>
:
[OperationContract]
[WebGet(UriTemplate = "/items/{id}", ResponseFormat = WebMessageFormat.Json)]
List<ItemService> GetItems(string id);
和Item
是:
[DataContract]
public class ItemService
{
[DataMember]
public int ItemID { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public Decimal OldPrice { get; set; }
[DataMember]
public Decimal NewPrice { get; set; }
[DataMember]
public string SaleStarts { get; set; }
[DataMember]
public string SaleEnds { get; set; }
}