How do you serialize javascript objects with methods using JSON?

前端 未结 3 1426
旧巷少年郎
旧巷少年郎 2020-12-21 12:03

I am looking for an enhancement to JSON that will also serialize methods. I have an object that acts as a collection of objects, and would like to serialize the methods of

3条回答
  •  春和景丽
    2020-12-21 12:42

    If you use WCF framework to develop RESTful web service, that is very easy to achieve. Simply create your data structure classes with your desired collection with DataContract, DataMember attributes.

    [DataContract]
    public class Foo
    {
        [DataMember]
         public string FooName {get;set;}
        [DataMember]
         public FooItem[] FooItems {get;set;}
    }
    
    
    [DataContract]
    public class FooItem
    {
        [DataMember]
        public string Name {get;set;}
    }
    

提交回复
热议问题