//例如有这么一个类
public class Button
{
private string _type;
private string _name;
public string type
{
get
{
return this._type;
}
set
{
this._type = value;
}
}
public string name
{
get
{
return this._name;
}
set
{
this._name = value;
}
}
}
//然后在Page_Load里给这个类实例化赋值
Button btn = new Button
{
type = "click" //这里只给type赋值 而不给name赋值
};
//然后用LitJson转换
string json = JsonMapper.ToJson(btn);
//输出得到的json为 {"type":"click","name":null} ,而我要的效果是name不显示,就像xml序列化那样,为空的属性就不输出