1.首先自定义一个JSON类,继承JsonConverter,把类的属性重写到JSON中.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GongHuiNewtonsoft.Json;
using GongHuiNewtonsoft.Json.Linq;
namespace JSONDemo
{
public class CustomConverter : JsonConverter
{
private readonly Type[] _types;
public CustomConverter(params Type[] types)
{
this._types = types;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
JToken t = JToken.FromObject(value);
if (t.Type != JTokenType.Object)
{
t.WriteTo(writer);
}
else
{
JObject jo = (JObject)t;
IList<string> propertyNameList = jo.Properties().Select(p => p.Name).ToList();
jo.AddFirst(new JProper