Advertisement

JSON通过自定义的非公共构造函数实现自定义的JSON解码器

阅读量:

首先定义一个类,并设置其构造函数为私有属性。

复制代码
 using System;

    
 using System.Collections.Generic;
    
 using System.Linq;
    
 using System.Text;
    
  
    
 namespace JSONDemo
    
 {
    
     public class Website
    
     {
    
     public string Url { get; set; }
    
  
    
     private Website()
    
     { }
    
  
    
     public Website(Website website)
    
     {
    
         if (website == null)
    
             throw new ArgumentNullException("website");
    
  
    
         this.Url = website.Url;
    
     }
    
     }
    
 }
    
    
    
    
  1. 为类中的属性分配JSON格式的数据,并进行反序列化

全部评论 (0)

还没有任何评论哟~