首页 新闻 赞助 找找看

LitJson将集合转换为json字符串的时候,怎么样不输出属性为null的结点?

0
悬赏园豆:30 [已解决问题] 解决于 2014-10-29 15:25

//例如有这么一个类

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序列化那样,为空的属性就不输出

ludi的主页 ludi | 初学一级 | 园豆:5
提问于:2014-09-10 16:03
< >
分享
最佳答案
0

换了一个组件Newtonsoft,问题解决了

ludi | 初学一级 |园豆:5 | 2014-10-29 15:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册