一、序列化成一个文件
1.JSON序列化成一个文件,此文件到记事本可以打开。首先先创建一个Movie对象.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JSONDemo
{
public class Movie
{
public string Name { get; set; }
public string Director { get; set; }
public int ReleaseYear { get; set; }
}
}
2.实例化movie对象,并给对象属性赋值。并且序列化成一个文件。包含了两种方法。源代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace JSONDemo
{
class Program
{
static void Main(string[] args)
{
Movie movie = new Movie
{
Name="HAPPY FEET 2",
Director="Judy Morris,Warren Coleman,George Miller",
ReleaseYear=2006
};