开发者

Rename the property in json serialization

开发者 https://www.devze.com 2023-01-07 21:48 出处:网络
In Json.net we can rename the property with [JsonPropertyAttribute(\"\")] , public class Foo { public string Foo1 { set; get; }

In Json.net we can rename the property with [JsonPropertyAttribute("")] ,

public class Foo {
 public string Foo1 { set; get; }
 public string Foo2 { set; get; }
}

and in the web service code behind:

[WebMethod]
public List <Foo> GetFoos() {
 List <Foo> post = new List < Foo > {
  new Foo(),
  new Foo(),
  new Foo()
 };
 return post;
}

How can I rena开发者_运维问答me the Foo1 property name to F1?


For example if you use DataContractJsonSerializer (see http://msdn.microsoft.com/en-us/library/bb412179.aspx) you can declare following

[DataContract(Name = "User")]
struct Person
{
   [DataMember(Name = "FirstName")]
   public string Name;

   [DataMember(Name = "LastName")]
   public string Surname;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消