一、使用JsonIgnoreAttribute忽略其属性序列化
1.创建一个Movie对象,并在其属性上添加JsonIgnore.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GongHuiNewtonsoft.Json;
namespace JSONDemo
{
public class Movie
{
public string Name { get; set; }
public string Director { get; set; }
[JsonIgnore]
public DateTime? LaunchDate { get; set; }
}
}
2.实例化对象Movie,并给其忽略的属性赋值。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using GongHuiNewtonsoft.Json;
using GongHuiNewtonsoft.Json.Serialization;
using GongHuiNewtonsoft.Json.Converters;
namespace JSONDemo
{
class Program
{
static void Main(string[] args)
{
Movie m = new Movie
{
Name = "爱情呼叫转移",