0

I am creating Web API where i am in need to add prefix to property. Is it possible to prefix some text with a property in controller. For eg. I am having a class A

public class Stats
{
   pubic bool IsStat { get; set; }
}

public HttpResponseMessage GetStats(Stats data)
{

}

The Web method GetStats is accessed by passing data as below

{Stat: true}

Now what I need to add Is prefix to the Stat property and so i will be getting true value for IsStat property in class Stats. Is it possible ?

4

1 回答 1

0

您有 2 个选项:

  1. 将您的IsStat属性重命名为Stat. 这应该与 json 数据匹配。

  2. 在你的类上使用[DataContract][DataMember]属性,并使用属性告诉反序列化器应该从属性中获取它的数据。StatsIsStatIsStatStat

[DataContract]
public class Stats
{
    [DataMember(Name = "Stat")]
    public bool IsStat { get; set; }
}
于 2013-05-27T05:33:39.150 回答