实体类
///<summary>
/// 用户信息
///</summary>
publicclass userInfo
{
privatestring _name;
publicstring name
{
get { return _name; }
set { _name = value; }
}

privatestring _screen_name;
publicstring screen_name
{
get { return _screen_name; }
set { _screen_name = value; }
}

privatestring _location;
publicstring location
{
get { return _location; }
set { _location = value; }
}
}
///<summary>
/// 消息
///</summary>
publicclass timeLine
{
privatestring _created_at;
publicstring created_at
{
get { return _created_at; }
set { _created_at = value; }
}

privatestring _text;
publicstring text
{
get { return _text; }
set { _text = value; }
}

privateint _id;
publicint id
{
get { return _id; }
set { _id = value; }
}

privatestring _mms_img_pre;
publicstring mms_img_pre
{
get { return _mms_img_pre; }
set { _mms_img_pre = value; }
}

private userInfo _user;
public userInfo user
{
get { return _user; }
set { _user = value; }
}
}

 

Serializing

1、序列化一个对像

代码
timeLine obj =new timeLine();
obj.created_at
="2010-7-15";
obj.id
=2589;
obj.mms_img_pre
="http://www.abc.com";
obj.text
="message text";
obj.user
= u;

this.Literal1.Text = JsonConvert.SerializeObject(obj, Formatting.Indented);

结果

{
"created_at": "2010-7-15",
"text": "message text",
"id": 2589,
"mms_img_pre": "http://www.abc.com",
"user": {
"name": "jack",
"screen_name": null,
"location": "shenzhen"
}
}

相关文章:

  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2022-02-23
  • 2021-08-22
  • 2021-12-23
  • 2022-02-28
相关资源
相似解决方案