C# json转对象

2021-05-17 11:28

阅读:599

标签:tac   net   dig   eric   str   expect   ace   memory   bin   

EnterpriseResponse09.json

技术图片技术图片
{
    "response_biz_content": {
        "MSG": "OK",
        "return_msg": "OK",
        "msg_id": "637067564513056852",
        "DATA": [{
            "SIZE": 1,
            "TCONF": {
                "C_EFFECTIVE_FLAG": "案件状态",
                "C_CASE_CODE": "案号",
                "C_SEX_NAME": "性别",
                "C_AREA_NAME": "地域名称",
                "C_GIST_UNIT": "作出执行依据单位",
                "C_BUESINESSENTITY": "企业法人姓名",
                "N_PARTY_TYPE_NAME": "标识自然人或企业法人",
                "D_DATA_DATE": "数据日期",
                "UNPERFORM_PART": "未履行部分",
                "N_AGE": "年龄",
                "PERFORMED_PART": "已履行部分",
                "C_PERFORMANCE": "被执行人的履行情况",
                "D_REG_DATE": "立案时间",
                "DUTY": "法律生效文书确定的义务",
                "C_INAME": "失信被执行人姓名/名称",
                "D_PUBLISH_DATE": "发布时间",
                "C_CARDNUM": "身份证号码/组织机构代码",
                "C_DISREPUT_TYPE_NAME": "失信被执行人具体情形",
                "C_COURT_NAME": "执行法院",
                "N_AREA_ID": "地域ID",
                "C_GIST_CID": "执行依据文号"
            },
            "MODEL": "09",
            "RISKTYPE": "失信被执行人",
            "RISKTYPEDES": "存在通过各种方法拒不执行法院判决的行为,俗称“老赖”。",
            "TOTALCOUNT": 1,
            "TDATA": [{
                "C_EFFECTIVE_FLAG": "1",
                "C_CASE_CODE": "(2008)沪213232法执字第01109号",
                "C_SEX_NAME": "",
                "C_AREA_NAME": "上海",
                "C_GIST_UNIT": "厦门市集美区人民法院",
                "C_BUESINESSENTITY": "李国华",
                "N_PARTY_TYPE_NAME": "",
                "D_DATA_DATE": "20190816",
                "UNPERFORM_PART": "",
                "N_AGE": "0",
                "PERFORMED_PART": "",
                "C_PERFORMANCE": "全部未履行",
                "D_REG_DATE": "20080902",
                "DUTY": "",
                "C_INAME": "79757239202-0",
                "D_PUBLISH_DATE": "20150106",
                "C_CARDNUM": "",
                "C_DISREPUT_TYPE_NAME": "其他有履行能力而拒不履行生效法律文书确定义务",
                "C_COURT_NAME": "上海市浦东新区人民法院",
                "N_AREA_ID": 672,
                "C_GIST_CID": "(2008)沪法执字第01109号"
            }]
        }],
        "return_code": "0000",
        "CODE": "02-000-203-0000"
    },
    "sign": "H8ESG0qXjYqZaA+rVcY0akVItL74kP11Mb2N4ZaABqL6/FZhU4HfxxKnn9NKU/DDbuIms7Udc89hqmWCzUMDIgKmbisvqimIddjj1RcLNEtiIxgbSwbCmb1KeEFw9gSZiS+7T6kzA86LuFw1IlJRIxU3DBxPzArY88+6RyZmyBQ="
}
View Code

TestResponse.cs

技术图片技术图片
    using System;
    using System.Runtime.CompilerServices;
    using System.Runtime.Serialization;
    
    [Serializable, DataContract]
    public class IcbcResponse
    {
        [DataMember]
        private int return_code = -1;
        [DataMember]
        private string return_msg = "unexpected error.";
        [DataMember]
        private string msg_id;
        
        public string getMsgId()
        {
            return this.msg_id;
        }
        
        public int getReturnCode()
        {
            return this.return_code;
        }
        
        public string getReturnMsg()
        {
            return this.return_msg;
        }
        
        public bool isSuccess()
        {
            return (this.return_code == 0);
        }
        
        public void setMsgId(string value)
        {
            this.msg_id = value;
        }
        
        public void setReturnCode(int value)
        {
            this.return_code = value;
        }
        
        public void setReturnMsg(string value)
        {
            this.return_msg = value;
        }
        
        [DataMember]
        public string MSG { get; set; }
        
        [DataMember]
        public string CODE { get; set; }
    }
View Code

EnterpriseResponse09.cs

技术图片技术图片
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Entity.Response.Enterprise
{
    public class EnterpriseResponse09 : TestResponse
    {
        [DataMember]
        public List DATA { get; set; }
        /// 
        /// 数据属性
        /// 
        public class DATAItem
        {
            /// 
            /// 数量
            /// 
            public int SIZE { get; set; }
            /// 
            /// 列名
            /// 
            public TCONF TCONF { get; set; }
            /// 
            /// 关联服务查询类型
            /// 
            public string MODEL { get; set; }
            /// 
            /// 失信被执行人
            /// 
            public string RISKTYPE { get; set; }
            /// 
            /// 存在通过各种方法拒不执行法院判决的行为,俗称“老赖”。
            /// 
            public string RISKTYPEDES { get; set; }
            /// 
            /// 数量
            /// 
            public int TOTALCOUNT { get; set; }
            /// 
            /// 数据
            /// 
            public List TDATA { get; set; }
            /// 
            /// 数据
            /// 
            public class TDATAItem
            {
                /// 
                /// 案号|Case Number    
                /// 
                public string C_CASE_CODE { get; set; }
                /// 
                /// 失信被执行人姓名/名称|Name/Designation    
                /// 
                public string C_INAME { get; set; }
                /// 
                /// 性别|Gender    
                /// 
                public string C_SEX_NAME { get; set; }
                /// 
                /// 年龄|Age    
                /// 
                public string N_AGE { get; set; }
                /// 
                /// 身份证号码/组织机构代码|ID card No./Org code    
                /// 
                public string C_CARDNUM { get; set; }
                /// 
                /// 企业法人姓名|Name of legal person    
                /// 
                public string C_BUESINESSENTITY { get; set; }
                /// 
                /// 执行法院|The Court    
                /// 
                public string C_COURT_NAME { get; set; }
                /// 
                /// 地域ID|Region ID    
                /// 
                public string N_AREA_ID { get; set; }
                /// 
                /// 地域名称|Region name    
                /// 
                public string C_AREA_NAME { get; set; }
                /// 
                /// 标识自然人或企业法人|Natural/legal person    
                /// 
                public string N_PARTY_TYPE_NAME { get; set; }
                /// 
                /// 执行依据文号|Exec. basis doc No.    
                /// 
                public string C_GIST_CID { get; set; }
                /// 
                /// 作出执行依据单位|Unit of execution basis    
                /// 
                public string C_GIST_UNIT { get; set; }
                /// 
                /// 法律生效文书确定的义务|Obligation of legal doc    
                /// 
                public string DUTY { get; set; }
                /// 
                /// 被执行人的履行情况|Perf. of executed    
                /// 
                public string C_PERFORMANCE { get; set; }
                /// 
                /// 失信被执行人具体情形|Situation of executed    
                /// 
                public string C_DISREPUT_TYPE_NAME { get; set; }
                /// 
                /// 发布时间|Time of release    
                /// 
                public string D_PUBLISH_DATE { get; set; }
                /// 
                /// 立案时间|Time of case filing    
                /// 
                public string D_REG_DATE { get; set; }
                /// 
                /// 已履行部分|Performed    
                /// 
                public string PERFORMED_PART { get; set; }
                /// 
                /// 未履行部分|To be performed    
                /// 
                public string UNPERFORM_PART { get; set; }
                /// 
                /// 案件状态|Case status    
                /// 
                public string C_EFFECTIVE_FLAG { get; set; }
                /// 
                /// 数据日期    
                /// 
                public string D_DATA_DATE { get; set; }
            }
        }
        /// 
        /// 数据描述
        /// 
        public class TCONF
        {
            /// 
            /// 案件状态
            /// 
            public string C_EFFECTIVE_FLAG { get; set; }
            /// 
            /// 案号
            /// 
            public string C_CASE_CODE { get; set; }
            /// 
            /// 性别
            /// 
            public string C_SEX_NAME { get; set; }
            /// 
            /// 地域名称
            /// 
            public string C_AREA_NAME { get; set; }
            /// 
            /// 作出执行依据单位
            /// 
            public string C_GIST_UNIT { get; set; }
            /// 
            /// 企业法人姓名
            /// 
            public string C_BUESINESSENTITY { get; set; }
            /// 
            /// 标识自然人或企业法人
            /// 
            public string N_PARTY_TYPE_NAME { get; set; }
            /// 
            /// 数据日期
            /// 
            public string D_DATA_DATE { get; set; }
            /// 
            /// 未履行部分
            /// 
            public string UNPERFORM_PART { get; set; }
            /// 
            /// 年龄
            /// 
            public string N_AGE { get; set; }
            /// 
            /// 已履行部分
            /// 
            public string PERFORMED_PART { get; set; }
            /// 
            /// 被执行人的履行情况
            /// 
            public string C_PERFORMANCE { get; set; }
            /// 
            /// 立案时间
            /// 
            public string D_REG_DATE { get; set; }
            /// 
            /// 法律生效文书确定的义务
            /// 
            public string DUTY { get; set; }
            /// 
            /// 失信被执行人姓名/名称
            /// 
            public string C_INAME { get; set; }
            /// 
            /// 发布时间
            /// 
            public string D_PUBLISH_DATE { get; set; }
            /// 
            /// 身份证号码/组织机构代码
            /// 
            public string C_CARDNUM { get; set; }
            /// 
            /// 失信被执行人具体情形
            /// 
            public string C_DISREPUT_TYPE_NAME { get; set; }
            /// 
            /// 执行法院
            /// 
            public string C_COURT_NAME { get; set; }
            /// 
            /// 地域ID
            /// 
            public string N_AREA_ID { get; set; }
            /// 
            /// 执行依据文号
            /// 
            public string C_GIST_CID { get; set; }
        }
    }
}
View Code

DataContractJsonSerializer

技术图片技术图片
            string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            string jsonfile = Path.Combine(baseDirectory, "EnterpriseResponse09.json");

            string responseJson = string.Empty;
            using (StreamReader r = new StreamReader(jsonfile))
            {
                responseJson = r.ReadToEnd();
            }
            string response_biz_content = "response_biz_content";
            int startIndex = (responseJson.IndexOf(response_biz_content) + response_biz_content.Length) + 2;
            string content = responseJson.Substring(startIndex, responseJson.LastIndexOf(",") - startIndex);

            EnterpriseResponse09 response = null;
            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(content)))
            {
                response = (EnterpriseResponse09)new DataContractJsonSerializer(typeof(EnterpriseResponse09)).ReadObject(stream);
            }

            //responseJson = "{\"response_biz_content\":{\"MSG\":\"OK\",\"return_msg\":\"OK\",\"msg_id\":\"637067564513056852\",\"DATA\":[{\"SIZE\":1,\"TCONF\":{\"C_EFFECTIVE_FLAG\":\"案件状态\",\"C_CASE_CODE\":\"案号\",\"C_SEX_NAME\":\"性别\",\"C_AREA_NAME\":\"地域名称\",\"C_GIST_UNIT\":\"作出执行依据单位\",\"C_BUESINESSENTITY\":\"企业法人姓名\",\"N_PARTY_TYPE_NAME\":\"标识自然人或企业法人\",\"D_DATA_DATE\":\"数据日期\",\"UNPERFORM_PART\":\"未履行部分\",\"N_AGE\":\"年龄\",\"PERFORMED_PART\":\"已履行部分\",\"C_PERFORMANCE\":\"被执行人的履行情况\",\"D_REG_DATE\":\"立案时间\",\"DUTY\":\"法律生效文书确定的义务\",\"C_INAME\":\"失信被执行人姓名/名称\",\"D_PUBLISH_DATE\":\"发布时间\",\"C_CARDNUM\":\"身份证号码/组织机构代码\",\"C_DISREPUT_TYPE_NAME\":\"失信被执行人具体情形\",\"C_COURT_NAME\":\"执行法院\",\"N_AREA_ID\":\"地域ID\",\"C_GIST_CID\":\"执行依据文号\"},\"MODEL\":\"09\",\"RISKTYPE\":\"失信被执行人\",\"RISKTYPEDES\":\"存在通过各种方法拒不执行法院判决的行为,俗称“老赖”。\",\"TOTALCOUNT\":1,\"TDATA\":[{\"C_EFFECTIVE_FLAG\":\"1\",\"C_CASE_CODE\":\"(2008)沪213232法执字第01109号\",\"C_SEX_NAME\":\"\",\"C_AREA_NAME\":\"上海\",\"C_GIST_UNIT\":\"厦门市集美区人民法院\",\"C_BUESINESSENTITY\":\"李国华\",\"N_PARTY_TYPE_NAME\":\"\",\"D_DATA_DATE\":\"20190816\",\"UNPERFORM_PART\":\"\",\"N_AGE\":\"0\",\"PERFORMED_PART\":\"\",\"C_PERFORMANCE\":\"全部未履行\",\"D_REG_DATE\":\"20080902\",\"DUTY\":\"\",\"C_INAME\":\"79757239202-0\",\"D_PUBLISH_DATE\":\"20150106\",\"C_CARDNUM\":\"\",\"C_DISREPUT_TYPE_NAME\":\"其他有履行能力而拒不履行生效法律文书确定义务\",\"C_COURT_NAME\":\"上海市浦东新区人民法院\",\"N_AREA_ID\":672,\"C_GIST_CID\":\"(2008)沪法执字第01109号\"}]}],\"return_code\":\"0000\",\"CODE\":\"02-000-203-0000\"},\"sign\":\"H8ESG0qXjYqZaA+rVcY0akVItL74kP11Mb2N4ZaABqL6/FZhU4HfxxKnn9NKU/DDbuIms7Udc89hqmWCzUMDIgKmbisvqimIddjj1RcLNEtiIxgbSwbCmb1KeEFw9gSZiS+7T6kzA86LuFw1IlJRIxU3DBxPzArY88+6RyZmyBQ=\"}";
View Code

 

C# json转对象

标签:tac   net   dig   eric   str   expect   ace   memory   bin   

原文地址:https://www.cnblogs.com/hofmann/p/11776020.html


评论


亲,登录后才可以留言!