Litjson Read Data Sample _ Practical Tips

Source: Internet
Author: User

1. Download and apply the Litjson,dll file

2. Construction of two categories;

Copy Code code as follows:

public class Jsondata
{
public string result {get; set;}
Public list<gamedata> Info {get; set;}
}


Public GameData ()
{ }
#region Model
private int _id;
private string _dept;
private string _sid;
private string _oldsid;
private string _userid;
private string _roleid;
private string _rolename;
private string _rolelevel;
private string _gold;
private string _money;
private string _inittime;
private string _lastlogin;
private string _querytime;
<summary>
///
</summary>
public int ID
{
set {_id = value;}
get {return _id;}
}
<summary>
Platform number
</summary>
public String Dept
{
set {_dept = value;}
get {return _dept;}
}
<summary>
Server number
</summary>
public string SID
{
set {_sid = value;}
get {return _sid;}
}
<summary>
Original server number
</summary>
public string Oldsid
{
set {_oldsid = value;}
get {return _oldsid;}
}
<summary>
User Platform ID
</summary>
public string UserID
{
set {_userid = value;}
get {return _userid;}
}
<summary>
///
</summary>
public string Roleid
{
set {_roleid = value;}
get {return _roleid;}
}
<summary>
Role name
</summary>
public string RoleName
{
set {_rolename = value;}
get {return _rolename;}
}
<summary>
Role level
</summary>
public string Rolelevel
{
set {_rolelevel = value;}
get {return _rolelevel;}
}
<summary>
Gold
</summary>
public string Gold
{
set {_gold = value;}
get {return _gold;}
}
<summary>
Silver
</summary>
public string
{
set {_money = value;}
get {return _money;}
}
<summary>
Role creation Time
</summary>
public string Inittime
{
set {_inittime = value;}
get {return _inittime;}
}
<summary>
Last Login time
</summary>
public string Lastlogin
{
set {_lastlogin = value;}
get {return _lastlogin;}
}
<summary>
Query time
</summary>
public string Querytime
{
set {_querytime = value;}
get {return _querytime;}
}
#endregion Model

3. Reading data

Copy Code code as follows:

String json_str = @ "{" "Result" ":" "1" "," "info": [{] "Sid" ":" "2" "," "RoleName" ":" "Po cuibai" "," "Roleid" ":" "900001" "," "" Lastlogin ":" "2014-01-08 10:54:52" "," "Inittime" ":" "2013-11-15 12:01:05.0" "," "Money" ":" "867" "," "Rolelevel" ":" "55" "," "userid" ":" "Athena" "," "Oldsid" ":" "1" "," "Gold" ":" "9992837" "," "Dept" ":" "", "" Querytime "", "", "" 2014-01-08 11:56:38 "},{" "Sid" ":" "2" "," "RoleName" ":" "poof" "," "Roleid" ":" "5700001" "," "Lastlogin" "," "2013-11-16 18:38:54" "," " Inittime "": "2013-11-16 18:25:45.0" "," "Money" ":" "0" "," "Rolelevel" ":" "," "," "userid" ":" "Athena" "," "Oldsid" ":" "1" "," "Gold" ":" "0" "," "Dept" ":" "" "," "Querytime" ":" "2014-01-08 11:56:38" "},{" "Sid" ":" "2" "," "RoleName" "" "," "Huiguang" "," "" Roleid "": "2800001" "," "Lastlogin" ":" "2013-11-15 15:00:07" "," "Inittime" ":" "2013-11-15 14:59:25.0" "," "Money" ":" "0" "," "Rolelevel" ":" "1" "," "userid" ":" "Athena" "," "Oldsid" ":" "1" "," "Gold" ":" "0" "," "Dept" ":" "," "Querytime" "" "" 2014-01-08 11:56:38 ""}]} ";

GameWindowsService.Common.JsonData Jsondata = Litjson.jsonmapper.toobject<gamewindowsservice.common.jsondata > (JSON_STR);

list<gamedata> gamedatalist = Jsondata.info;
foreach (Var gamedata in gamedatalist)
{
Common.Common.WriteFile (Gamedata.add (). ToString ());
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.