C# Newtonsoft.Json 使用


            byte[] bUserInfoSearch = new byte[1024 * 10]; //10kb大小
            Marshal.Copy(lpBuffer, bUserInfoSearch, 0, bUserInfoSearch.Length);
            string strUserInfoSearch = System.Text.Encoding.UTF8.GetString(bUserInfoSearch);

            CUserInfoSearch  m_JsonUserInfoSearch = new CUserInfoSearch();
            //序列化這個字符串
            m_JsonUserInfoSearch = JsonConvert.DeserializeObject<CUserInfoSearch>(strUserInfoSearch);
     public class CUserInfoSearch
        {
            public CUserInfoSearchContent UserInfoSearch { get; set; }
        }
        public class CUserInfoSearchContent
        {
            public string searchID { get; set; }
public string responseStatusStrg { get; set; } //查詢狀態字符串描述: OK-查詢結束, MORE-還有數據等待查詢, NO MATCH-沒有匹配數據
            public int numOfMatches { get; set; } //本次返回的記錄條數
         
public int totalMatches { get; set; } //符合條件的記錄總條數
public List<CUserInfoContent> UserInfo { get; set; } }
  public class CUserInfoContent
        {
            public string employeeNo { get; set; }
            public string name { get; set; }
            public string userType { get; set; }
            public bool closeDelayEnabled { get; set; }
            public CVaild Valid { get; set; }
            public string belongGroup { get; set; }
            public string password { get; set; }
            public string doorRight { get; set; }
            public List<CRightPlan> RightPlan { get; set; }
            public int maxOpenDoorTime { get; set; }
            public int openDoorTime { get; set; }
            public int roomNumber { get; set; }
            public int floorNumber { get; set; }
            public bool doubleLockRight { get; set; }
            public bool alwaysOpenRight { get; set; }
            public bool localUIRight { get; set; }
            public string userVerifyMode { get; set; }
            public bool checkUser { get; set; }
        }
        public class CVaild
        {
            public bool enable { get; set; }
            public string beginTime { get; set; }
            public string endTime { get; set; }
            public string timeType { get; set; }
        }
       public class CRightPlan
        {
            public int doorNo { get; set; }
            public string planTemplateNo { get; set; }
        }

json字符串為

{
    "UserInfoSearch":    {
        "searchID":    "1",
        "responseStatusStrg":    "MORE",
        "numOfMatches":    2,
        "totalMatches":    4,
        "UserInfo":    [{
                "employeeNo":    "1",
                "name":    "管理員(131374",
                "userType":    "normal",
                "closeDelayEnabled":    false,
                "Valid":    {
                    "enable":    false,
                    "beginTime":    "0-00-00T00:00:00",
                    "endTime":    "0-00-00T00:00:00",
                    "timeType":    "local"
                },
                "belongGroup":    "",
                "password":    "",
                "doorRight":    "1",
                "RightPlan":    [{
                        "doorNo":    1,
                        "planTemplateNo":    "1"
                    }],
                "maxOpenDoorTime":    0,
                "openDoorTime":    0,
                "roomNumber":    1,
                "floorNumber":    1,
                "localUIRight":    false,
                "numOfCard":    0,
                "numOfFP":    0,
                "numOfFace":    0
            }, {
                "employeeNo":    "2",
                "name":    "123456",
                "userType":    "normal",
                "closeDelayEnabled":    false,
                "Valid":    {
                    "enable":    false,
                    "beginTime":    "0-00-00T00:00:00",
                    "endTime":    "0-00-00T00:00:00",
                    "timeType":    "local"
                },
                "belongGroup":    "",
                "password":    "",
                "doorRight":    "1",
                "RightPlan":    [{
                        "doorNo":    1,
                        "planTemplateNo":    "1"
                    }],
                "maxOpenDoorTime":    0,
                "openDoorTime":    0,
                "roomNumber":    1,
                "floorNumber":    1,
                "localUIRight":    false,
                "numOfCard":    0,
                "numOfFP":    0,
                "numOfFace":    1
            }]
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM