将复杂(嵌套)JSON反序列化为C#对象
我一直致力于从API反序列化复杂的JSON响应。我刚接触C#和.NET,所以我真的不知道如何继续 我想做的是: 我希望收集JSON响应中的所有项,并将它们放在键值对中,然后将它们返回到控制台应用程序中的列表中进行测试 当我调试时,它工作得非常好,我可以看到它按照预期映射了所有的键值对。我的任务是在控制台应用程序中返回列表中的所有内容 这是我为“模型”类编写的代码 这是我的“WriteLine”命令代码,用于尝试在列表中列出所有键值对将复杂(嵌套)JSON反序列化为C#对象,c#,.net,arrays,json,serialization,C#,.net,Arrays,Json,Serialization,我一直致力于从API反序列化复杂的JSON响应。我刚接触C#和.NET,所以我真的不知道如何继续 我想做的是: 我希望收集JSON响应中的所有项,并将它们放在键值对中,然后将它们返回到控制台应用程序中的列表中进行测试 当我调试时,它工作得非常好,我可以看到它按照预期映射了所有的键值对。我的任务是在控制台应用程序中返回列表中的所有内容 这是我为“模型”类编写的代码 这是我的“WriteLine”命令代码,用于尝试在列表中列出所有键值对 using System; class ConsoleApp
using System;
class ConsoleAppClass
{
static void Main()
{
string json2 = @"{""code"":200,""message"":""OK"",""profiling"":null,""count"":6,""skip"":0,""limit"":50,""next_page"":null,""previous_page"":null,""additional_meta"":{""$and"":[{""deleted"":false},{""$or"":[{""holder_id"":{""$id"":""5543677f37c6b65f008b46e4""}},{""root.holder._id"":{""$id"":""5543677f37c6b65f008b46e4""}}]}]},""data"":[{""_id"":""5825c6f6de22ae00632e86f3"",""ean"":""659842"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""5824790e3d214b006271c515"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:26:14+0000"",""children"":[],""address"":""Kungsgatan 2"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""heat"",""consumption_stats"":{""energy"":{""hour"":{""count"":26275,""sum"":6546140,""max"":930,""last"":2016123021,""min"":0,""first"":2014010101},""day"":{""count"":1091,""sum"":6522120,""max"":18900,""last"":20161229,""min"":1180,""first"":20140102},""month"":{""count"":33,""sum"":5727310,""max"":387190,""last"":201708,""min"":49750,""first"":201402}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c76920fe9b006308e412"",""ean"":""735999999564879216"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""5824790e3d214b006271c510"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:28:09+0000"",""children"":[],""address"":""Kungsgatan 2"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""electricity"",""consumption_stats"":{""energy"":{""hour"":{""count"":25953,""sum"":311714.628,""max"":34.3,""last"":2016121709,""min"":0,""first"":2014010101},""day"":{""count"":1080,""sum"":311302.328,""max"":689,""last"":20161216,""min"":141.1,""first"":20140102},""month"":{""count"":35,""sum"":306915.54,""max"":13704.72,""last"":201708,""min"":6013.932,""first"":201402}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c84b22c8aa00623d65a5"",""ean"":""6934363"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b4672"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:31:55+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""gas"",""consumption_stats"":{""energy"":{""month"":{""count"":24,""sum"":42656.62,""max"":8890.65,""last"":201708,""min"":104.57,""first"":201501},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c85320fe9b006308e41d"",""ean"":""5896584"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b466c"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:32:03+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""heat"",""consumption_stats"":{""energy"":{""month"":{""count"":57,""sum"":3592320,""max"":173000,""last"":201709,""min"":2000,""first"":201301},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c85920fe9b0061547253"",""ean"":""735999666123123123"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b4669"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:32:09+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""electricity"",""consumption_stats"":{""energy"":{""month"":{""count"":45,""sum"":141604.36,""max"":6488.2,""last"":201709,""min"":1759.64,""first"":201401},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c85d22c8aa00606b9dd5"",""ean"":""1200004"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b466f"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:32:13+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""cooling"",""consumption_stats"":{""energy"":{""month"":{""count"":33,""sum"":902350,""max"":92560,""last"":201709,""min"":9730,""first"":201501},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null}]}";
var items = JsonConvert.DeserializeObject<List<ModelsClass.Rootobject>>(json2);
foreach (ModelsClass.Rootobject value in items)
{
Console.WriteLine(value, items);
}
Console.ReadKey();
}
}
使用系统;
类控制台类
{
静态void Main()
{
字符串json2=@“{”代码“:200”,“消息“:”确定“,”评测“:null”,“计数“:6”,“跳过“:0”,“限制“:50”,“下一页“:null”,“上一页“:null”,“附加的{”元“:{”和“:[{”已删除“:false},{”或“:[{”持有者id“:{”持有者id“:{”id“:“5543677f37c6b65f008b46e4”},{root.holder“:{”根用户id“:{id“:{43677F37F008B6C67C6 id:”,{B408B4B6C6 id:}“5825c6f6de22ae00632e86f3”“ean”“:”“659842”“名称”“:null”“持有人”“:{”“id”“:”“5543677f37c6b65f008b46e4”“名称”“:”“示例帐户”“用户名”“:”someone@example.com“}”“根”“:{”“id”“:”“5824790e3d214b006271c515”“持有人”“:{”“id”“:”“577fd0170c8a335c008b45fe”“名称”“:”“Rob Harvey公用事业公司”“实体类型”“:”“公用事业提供商”“}”},“转让人”:{“_id”:“577fd0170c8a335c008b45fe”,“名称”:“Rob Harvey公用事业公司”,“用户名”:“Rob Harvey公用事业公司”-utility@example.com“,”经理“:{”“id”“:null}}“,”已创建“:”2016-11-11T13:26:14+0000“,”子项“:[],”地址“:”Kungsgatan 2“,”时区“:”Etc\/GMT-1“,”控制级别“:”共享“,”计费类别“:”拥有的电能表消耗量,发电量,能源消耗量,能源消耗量,能源消耗量,能源消耗量,能源消耗量,能源消耗量,能源消耗量,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗,能源消耗min“:1180“,”first“:20140102}“,”month“:{”count“:33“,”sum“:5727310“,”max“:387190“,”last“:201708“,”min“:49750“,”first“,”first“:201402}}}“,”cost_stats“:{}”,“Reads_stats”“:null“,”has_active_投诉“:false”,“representation”“:null”,“representation”“:null”,“open(channel(ID”“:null”,“on(hold”“:null”,“on(hold”“,”空”,“last)sla(sla电表读数器“:[],”集合窗口“:5”,“备忘录“:null},{”电表id“:”5825c76920fe9b006308e412“,”ean“:”7359999564879216“,”名称“:”null“,”持有人“:{”电表id“:”5543677f37c6b65f008b46e4“,”名称“:”示例帐户“,”用户名“:”someone@example.com“}”、“根”:{”“id”:”“5824790e3d214b006271c510”“持有者”:{”“id”:”577fd0170c8a335c008b45fe“名称”:“Rob Harvey公用事业公司”、“实体类型”:“公用事业提供商”}、“转让人”:{“id”:“577fd0170c8a335c008b45fe”、“名称”:“Rob Harvey公用事业公司”、“用户名”:“RobveyUtilityCompany”-utility@example.com“”管理器“”:{“\u id”“:null}}>,”已创建“”:“”2016-11-11T13:28:09+0000“”,“”子项“”:[],“”地址“:”Kungsgatan 2“,”时区“:”Etc\/GMT-1“,”控制级别“:”共享“,”计费类别“:”自有电表消耗“,”发电“:1“,”标签“:[”,”方框“:”活动“,”撤销“:”假“,”度量“:[”能量“,”类型“:”电“,”消耗统计“:”,“{”能量“:{”小时“:{”计数“:25953“,”总和“:311714.628”,“最大值“:34.3”,“最后一次”:2016121709,“最小值”:0,“第一次”:201401001},“日”:日:{“计数”:1080,“总和”:311302.328,“最大值”:689,“最后一次”:20161216,“最小值”:141.1,“第一次”:20140102},“月”:月:{“计数”:35,“总和”:306915.54,“最大值”:13704.72,“最后一次”:201708,“最小值”:6013.932,“第一次”:201402},“成本统计”:空值:{“有虚假投诉,}”表示法“:null”、“开放频道\u id”“:null”、“保持状态”:null、“最后一次\u sla\u注释”:null、“位置”:null、“元数据”:{}、“仪表读卡器”:[]、“集合窗口”:5、“备忘录”:null}、{“备忘录”:“保留”:“5825c84b22c8aa00623d65a5”、“ean”:“6934363”、“名称”:null、“持有人”:{“帐户id”:“5543677F37B65F008B46E4”;“用户名示例帐户”:“用户名”:""someone@example.com“}”“根”“:{”“id”“:”“577fdd960c8a335c008b4672”“持有人”“:{”“id”“:”“577fd0170c8a335c008b45fe”“名称”“:”“Rob Harvey公用事业公司”“实体类型”“:”“公用事业提供商”“}}”“转让人”“:{”“id”“:”“577fd0170c8a335c008b45fe”“名称”“:”“Rob Harvey公用事业公司”“用户名”“:”“Robveyutilitycompany”-utility@example.com"“,”经理“:{”“\u id”“:null}}“,”已创建“:”2016-11-11T13:31:55+0000“,”子项“:[],”地址“:”Gr\u00e4nsv\u00e4gen 12B“,”时区“:”Etc\/GMT-1“,”控制级别“:”共享“,”计费类别“:”自有电表消耗“,”发电“:”1“,”标签“:[],”盒子“:”活动“,”撤销“:”假“,”度量“:[”能源“,”类型“:”气体“,”“消耗统计数据:{”“能源:{”“月份:{”“计数”“:24”“总和”“:42656.62”“最大值”“:8890.65”“最后一次”“:201708”“最小值”“:104.57”“第一次”“:201501}”“小时”“:{”“第一次”“:null”“最后一次”“:null”“总和”“:null”“max”“:null”“min”“:null”“count”“:0}”“日”“:{”“第一次”“:null”“最后一次”“:null”“sum”“:null”“max”“:null”“min”“:null”“count阅读“统计数据”:null,“有活动的投诉”:false,“表示”:null,“开放的频道id”:null,“保持”:null,“最后的sla注释”:null,“位置”:null,“元数据”:“{}”,“仪表读卡器”:[],“收集窗口”:5,“备忘录”:null},{“id”:“5825c85320fe9b006308e41d”,“ean”:“5896584”,“名称”:null,“持有者”:5543677f37c6b65f008b46e4“名称”:“示例帐户”“用户名”:”someone@example.com“}”“根”“:{”“id”“:”“577fdd960c8a335c008b466c”“持有人”“:{”“id”“:”“577fd0170c8a335c008b45fe”“名称”“:”“Rob Harvey公用事业公司”“实体类型”“:”“公用事业提供商”“}}”“转让人”“:{”“id”“:”“577fd0170c8a335c008b45fe”“名称”“:”Rob Harvey公用事业公司“”“”用户名“”:“”R
using System;
class ConsoleAppClass
{
static void Main()
{
string json2 = @"{""code"":200,""message"":""OK"",""profiling"":null,""count"":6,""skip"":0,""limit"":50,""next_page"":null,""previous_page"":null,""additional_meta"":{""$and"":[{""deleted"":false},{""$or"":[{""holder_id"":{""$id"":""5543677f37c6b65f008b46e4""}},{""root.holder._id"":{""$id"":""5543677f37c6b65f008b46e4""}}]}]},""data"":[{""_id"":""5825c6f6de22ae00632e86f3"",""ean"":""659842"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""5824790e3d214b006271c515"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:26:14+0000"",""children"":[],""address"":""Kungsgatan 2"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""heat"",""consumption_stats"":{""energy"":{""hour"":{""count"":26275,""sum"":6546140,""max"":930,""last"":2016123021,""min"":0,""first"":2014010101},""day"":{""count"":1091,""sum"":6522120,""max"":18900,""last"":20161229,""min"":1180,""first"":20140102},""month"":{""count"":33,""sum"":5727310,""max"":387190,""last"":201708,""min"":49750,""first"":201402}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c76920fe9b006308e412"",""ean"":""735999999564879216"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""5824790e3d214b006271c510"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:28:09+0000"",""children"":[],""address"":""Kungsgatan 2"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""electricity"",""consumption_stats"":{""energy"":{""hour"":{""count"":25953,""sum"":311714.628,""max"":34.3,""last"":2016121709,""min"":0,""first"":2014010101},""day"":{""count"":1080,""sum"":311302.328,""max"":689,""last"":20161216,""min"":141.1,""first"":20140102},""month"":{""count"":35,""sum"":306915.54,""max"":13704.72,""last"":201708,""min"":6013.932,""first"":201402}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c84b22c8aa00623d65a5"",""ean"":""6934363"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b4672"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:31:55+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""gas"",""consumption_stats"":{""energy"":{""month"":{""count"":24,""sum"":42656.62,""max"":8890.65,""last"":201708,""min"":104.57,""first"":201501},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c85320fe9b006308e41d"",""ean"":""5896584"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b466c"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:32:03+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""heat"",""consumption_stats"":{""energy"":{""month"":{""count"":57,""sum"":3592320,""max"":173000,""last"":201709,""min"":2000,""first"":201301},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c85920fe9b0061547253"",""ean"":""735999666123123123"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b4669"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:32:09+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""electricity"",""consumption_stats"":{""energy"":{""month"":{""count"":45,""sum"":141604.36,""max"":6488.2,""last"":201709,""min"":1759.64,""first"":201401},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c85d22c8aa00606b9dd5"",""ean"":""1200004"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b466f"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:32:13+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""cooling"",""consumption_stats"":{""energy"":{""month"":{""count"":33,""sum"":902350,""max"":92560,""last"":201709,""min"":9730,""first"":201501},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null}]}";
var items = JsonConvert.DeserializeObject<List<ModelsClass.Rootobject>>(json2);
foreach (ModelsClass.Rootobject value in items)
{
Console.WriteLine(value, items);
}
Console.ReadKey();
}
}
Dictionary<string, string> myDict = new Dictionary<string, string>();
Type t = data.GetType();
foreach (PropertyInfo pi in t.GetProperties())
{
myDict[pi.Name] = pi.GetValue(data,null).ToString();
}
{
"code":200,
"message":"OK",
"profiling":null,
"count":6,
"skip":0,
"limit":50,
"next_page":null,
"previous_page":null,
"additional_meta":{
"$and":[
{
"deleted":false
},
{
"$or":[
{
"holder_id":{
"$id":"5543677f37c6b65f008b46e4"
}
},
{
"root.holder._id":{
"$id":"5543677f37c6b65f008b46e4"
}
}
]
}
]
},
"data":[
{
"_id":"5825c6f6de22ae00632e86f3",
"ean":"659842",
"name":null,
"holder":{
"_id":"5543677f37c6b65f008b46e4",
"name":"Example account",
"username":"someone@example.com"
},
"root":{
"_id":"5824790e3d214b006271c515",
"holder":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"entity_type":"utility_provider"
}
},
"assigner":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"username":"RobHarveyUtilityCompany-utility@example.com",
"manager":{
"_id":null
}
},
"created":"2016-11-11T13:26:14+0000",
"children":[
],
"address":"Kungsgatan 2",
"timezone":"Etc\/GMT-1",
"control_level":"shared",
"billing_category":"owned_meter_consumption",
"generation":1,
"tags":[
],
"box":"active",
"revoked":false,
"metrics":[
"energy"
],
"type":"heat",
"consumption_stats":{
"energy":{
"hour":{
"count":26275,
"sum":6546140,
"max":930,
"last":2016123021,
"min":0,
"first":2014010101
},
"day":{
"count":1091,
"sum":6522120,
"max":18900,
"last":20161229,
"min":1180,
"first":20140102
},
"month":{
"count":33,
"sum":5727310,
"max":387190,
"last":201708,
"min":49750,
"first":201402
}
}
},
"cost_stats":{
},
"readings_stats":null,
"has_active_complaints":false,
"representation":null,
"open_channel_ids":null,
"on_hold":null,
"last_sla_comment":null,
"location":null,
"meta_data":{
},
"meter_readers":[
],
"collection_window":5,
"memo":null
},
{
"_id":"5825c76920fe9b006308e412",
"ean":"735999999564879216",
"name":null,
"holder":{
"_id":"5543677f37c6b65f008b46e4",
"name":"Example account",
"username":"someone@example.com"
},
"root":{
"_id":"5824790e3d214b006271c510",
"holder":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"entity_type":"utility_provider"
}
},
"assigner":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"username":"RobHarveyUtilityCompany-utility@example.com",
"manager":{
"_id":null
}
},
"created":"2016-11-11T13:28:09+0000",
"children":[
],
"address":"Kungsgatan 2",
"timezone":"Etc\/GMT-1",
"control_level":"shared",
"billing_category":"owned_meter_consumption",
"generation":1,
"tags":[
],
"box":"active",
"revoked":false,
"metrics":[
"energy"
],
"type":"electricity",
"consumption_stats":{
"energy":{
"hour":{
"count":25953,
"sum":311714.628,
"max":34.3,
"last":2016121709,
"min":0,
"first":2014010101
},
"day":{
"count":1080,
"sum":311302.328,
"max":689,
"last":20161216,
"min":141.1,
"first":20140102
},
"month":{
"count":35,
"sum":306915.54,
"max":13704.72,
"last":201708,
"min":6013.932,
"first":201402
}
}
},
"cost_stats":{
},
"readings_stats":null,
"has_active_complaints":false,
"representation":null,
"open_channel_ids":null,
"on_hold":null,
"last_sla_comment":null,
"location":null,
"meta_data":{
},
"meter_readers":[
],
"collection_window":5,
"memo":null
},
{
"_id":"5825c84b22c8aa00623d65a5",
"ean":"6934363",
"name":null,
"holder":{
"_id":"5543677f37c6b65f008b46e4",
"name":"Example account",
"username":"someone@example.com"
},
"root":{
"_id":"577fdd960c8a335c008b4672",
"holder":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"entity_type":"utility_provider"
}
},
"assigner":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"username":"RobHarveyUtilityCompany-utility@example.com",
"manager":{
"_id":null
}
},
"created":"2016-11-11T13:31:55+0000",
"children":[
],
"address":"Gr\u00e4nsv\u00e4gen 12B",
"timezone":"Etc\/GMT-1",
"control_level":"shared",
"billing_category":"owned_meter_consumption",
"generation":1,
"tags":[
],
"box":"active",
"revoked":false,
"metrics":[
"energy"
],
"type":"gas",
"consumption_stats":{
"energy":{
"month":{
"count":24,
"sum":42656.62,
"max":8890.65,
"last":201708,
"min":104.57,
"first":201501
},
"hour":{
"first":null,
"last":null,
"sum":null,
"max":null,
"min":null,
"count":0
},
"day":{
"first":null,
"last":null,
"sum":null,
"max":null,
"min":null,
"count":0
}
}
},
"cost_stats":{
},
"readings_stats":null,
"has_active_complaints":false,
"representation":null,
"open_channel_ids":null,
"on_hold":null,
"last_sla_comment":null,
"location":null,
"meta_data":{
},
"meter_readers":[
],
"collection_window":5,
"memo":null
},
{
"_id":"5825c85320fe9b006308e41d",
"ean":"5896584",
"name":null,
"holder":{
"_id":"5543677f37c6b65f008b46e4",
"name":"Example account",
"username":"someone@example.com"
},
"root":{
"_id":"577fdd960c8a335c008b466c",
"holder":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"entity_type":"utility_provider"
}
},
"assigner":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"username":"RobHarveyUtilityCompany-utility@example.com",
"manager":{
"_id":null
}
},
"created":"2016-11-11T13:32:03+0000",
"children":[
],
"address":"Gr\u00e4nsv\u00e4gen 12B",
"timezone":"Etc\/GMT-1",
"control_level":"shared",
"billing_category":"owned_meter_consumption",
"generation":1,
"tags":[
],
"box":"active",
"revoked":false,
"metrics":[
"energy"
],
"type":"heat",
"consumption_stats":{
"energy":{
"month":{
"count":57,
"sum":3592320,
"max":173000,
"last":201709,
"min":2000,
"first":201301
},
"hour":{
"first":null,
"last":null,
"sum":null,
"max":null,
"min":null,
"count":0
},
"day":{
"first":null,
"last":null,
"sum":null,
"max":null,
"min":null,
"count":0
}
}
},
"cost_stats":{
},
"readings_stats":null,
"has_active_complaints":false,
"representation":null,
"open_channel_ids":null,
"on_hold":null,
"last_sla_comment":null,
"location":null,
"meta_data":{
},
"meter_readers":[
],
"collection_window":5,
"memo":null
},
{
"_id":"5825c85920fe9b0061547253",
"ean":"735999666123123123",
"name":null,
"holder":{
"_id":"5543677f37c6b65f008b46e4",
"name":"Example account",
"username":"someone@example.com"
},
"root":{
"_id":"577fdd960c8a335c008b4669",
"holder":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"entity_type":"utility_provider"
}
},
"assigner":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"username":"RobHarveyUtilityCompany-utility@example.com",
"manager":{
"_id":null
}
},
"created":"2016-11-11T13:32:09+0000",
"children":[
],
"address":"Gr\u00e4nsv\u00e4gen 12B",
"timezone":"Etc\/GMT-1",
"control_level":"shared",
"billing_category":"owned_meter_consumption",
"generation":1,
"tags":[
],
"box":"active",
"revoked":false,
"metrics":[
"energy"
],
"type":"electricity",
"consumption_stats":{
"energy":{
"month":{
"count":45,
"sum":141604.36,
"max":6488.2,
"last":201709,
"min":1759.64,
"first":201401
},
"hour":{
"first":null,
"last":null,
"sum":null,
"max":null,
"min":null,
"count":0
},
"day":{
"first":null,
"last":null,
"sum":null,
"max":null,
"min":null,
"count":0
}
}
},
"cost_stats":{
},
"readings_stats":null,
"has_active_complaints":false,
"representation":null,
"open_channel_ids":null,
"on_hold":null,
"last_sla_comment":null,
"location":null,
"meta_data":{
},
"meter_readers":[
],
"collection_window":5,
"memo":null
},
{
"_id":"5825c85d22c8aa00606b9dd5",
"ean":"1200004",
"name":null,
"holder":{
"_id":"5543677f37c6b65f008b46e4",
"name":"Example account",
"username":"someone@example.com"
},
"root":{
"_id":"577fdd960c8a335c008b466f",
"holder":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"entity_type":"utility_provider"
}
},
"assigner":{
"_id":"577fd0170c8a335c008b45fe",
"name":"Rob Harvey Utility Company",
"username":"RobHarveyUtilityCompany-utility@example.com",
"manager":{
"_id":null
}
},
"created":"2016-11-11T13:32:13+0000",
"children":[
],
"address":"Gr\u00e4nsv\u00e4gen 12B",
"timezone":"Etc\/GMT-1",
"control_level":"shared",
"billing_category":"owned_meter_consumption",
"generation":1,
"tags":[
],
"box":"active",
"revoked":false,
"metrics":[
"energy"
],
"type":"cooling",
"consumption_stats":{
"energy":{
"month":{
"count":33,
"sum":902350,
"max":92560,
"last":201709,
"min":9730,
"first":201501
},
"hour":{
"first":null,
"last":null,
"sum":null,
"max":null,
"min":null,
"count":0
},
"day":{
"first":null,
"last":null,
"sum":null,
"max":null,
"min":null,
"count":0
}
}
},
"cost_stats":{
},
"readings_stats":null,
"has_active_complaints":false,
"representation":null,
"open_channel_ids":null,
"on_hold":null,
"last_sla_comment":null,
"location":null,
"meta_data":{
},
"meter_readers":[
],
"collection_window":5,
"memo":null
}
]
}
static void Main()
{
string json2 = @"{'code':200,'message':'OK','profiling':null,'count':6,'skip':0,'limit':50,'next_page':null,'previous_page':null,'additional_meta':{'$and':[{'deleted':false},{'$or':[{'holder_id':{'$id':'5543677f37c6b65f008b46e4'}},{'root.holder._id':{'$id':'5543677f37c6b65f008b46e4'}}]}]},'data':[{'_id':'5825c6f6de22ae00632e86f3','ean':'659842','name':null,'holder':{'_id':'5543677f37c6b65f008b46e4','name':'Example account','username':'someone@example.com'},'root':{'_id':'5824790e3d214b006271c515','holder':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','entity_type':'utility_provider'}},'assigner':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','username':'RobHarveyUtilityCompany-utility@example.com','manager':{'_id':null}},'created':'2016-11-11T13:26:14+0000','children':[],'address':'Kungsgatan 2','timezone':'Etc\/GMT-1','control_level':'shared','billing_category':'owned_meter_consumption','generation':1,'tags':[],'box':'active','revoked':false,'metrics':['energy'],'type':'heat','consumption_stats':{'energy':{'hour':{'count':26275,'sum':6546140,'max':930,'last':2016123021,'min':0,'first':2014010101},'day':{'count':1091,'sum':6522120,'max':18900,'last':20161229,'min':1180,'first':20140102},'month':{'count':33,'sum':5727310,'max':387190,'last':201708,'min':49750,'first':201402}}},'cost_stats':{},'readings_stats':null,'has_active_complaints':false,'representation':null,'open_channel_ids':null,'on_hold':null,'last_sla_comment':null,'location':null,'meta_data':{},'meter_readers':[],'collection_window':5,'memo':null},{'_id':'5825c76920fe9b006308e412','ean':'735999999564879216','name':null,'holder':{'_id':'5543677f37c6b65f008b46e4','name':'Example account','username':'someone@example.com'},'root':{'_id':'5824790e3d214b006271c510','holder':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','entity_type':'utility_provider'}},'assigner':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','username':'RobHarveyUtilityCompany-utility@example.com','manager':{'_id':null}},'created':'2016-11-11T13:28:09+0000','children':[],'address':'Kungsgatan 2','timezone':'Etc\/GMT-1','control_level':'shared','billing_category':'owned_meter_consumption','generation':1,'tags':[],'box':'active','revoked':false,'metrics':['energy'],'type':'electricity','consumption_stats':{'energy':{'hour':{'count':25953,'sum':311714.628,'max':34.3,'last':2016121709,'min':0,'first':2014010101},'day':{'count':1080,'sum':311302.328,'max':689,'last':20161216,'min':141.1,'first':20140102},'month':{'count':35,'sum':306915.54,'max':13704.72,'last':201708,'min':6013.932,'first':201402}}},'cost_stats':{},'readings_stats':null,'has_active_complaints':false,'representation':null,'open_channel_ids':null,'on_hold':null,'last_sla_comment':null,'location':null,'meta_data':{},'meter_readers':[],'collection_window':5,'memo':null},{'_id':'5825c84b22c8aa00623d65a5','ean':'6934363','name':null,'holder':{'_id':'5543677f37c6b65f008b46e4','name':'Example account','username':'someone@example.com'},'root':{'_id':'577fdd960c8a335c008b4672','holder':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','entity_type':'utility_provider'}},'assigner':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','username':'RobHarveyUtilityCompany-utility@example.com','manager':{'_id':null}},'created':'2016-11-11T13:31:55+0000','children':[],'address':'Gr\u00e4nsv\u00e4gen 12B','timezone':'Etc\/GMT-1','control_level':'shared','billing_category':'owned_meter_consumption','generation':1,'tags':[],'box':'active','revoked':false,'metrics':['energy'],'type':'gas','consumption_stats':{'energy':{'month':{'count':24,'sum':42656.62,'max':8890.65,'last':201708,'min':104.57,'first':201501},'hour':{'first':null,'last':null,'sum':null,'max':null,'min':null,'count':0},'day':{'first':null,'last':null,'sum':null,'max':null,'min':null,'count':0}}},'cost_stats':{},'readings_stats':null,'has_active_complaints':false,'representation':null,'open_channel_ids':null,'on_hold':null,'last_sla_comment':null,'location':null,'meta_data':{},'meter_readers':[],'collection_window':5,'memo':null},{'_id':'5825c85320fe9b006308e41d','ean':'5896584','name':null,'holder':{'_id':'5543677f37c6b65f008b46e4','name':'Example account','username':'someone@example.com'},'root':{'_id':'577fdd960c8a335c008b466c','holder':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','entity_type':'utility_provider'}},'assigner':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','username':'RobHarveyUtilityCompany-utility@example.com','manager':{'_id':null}},'created':'2016-11-11T13:32:03+0000','children':[],'address':'Gr\u00e4nsv\u00e4gen 12B','timezone':'Etc\/GMT-1','control_level':'shared','billing_category':'owned_meter_consumption','generation':1,'tags':[],'box':'active','revoked':false,'metrics':['energy'],'type':'heat','consumption_stats':{'energy':{'month':{'count':57,'sum':3592320,'max':173000,'last':201709,'min':2000,'first':201301},'hour':{'first':null,'last':null,'sum':null,'max':null,'min':null,'count':0},'day':{'first':null,'last':null,'sum':null,'max':null,'min':null,'count':0}}},'cost_stats':{},'readings_stats':null,'has_active_complaints':false,'representation':null,'open_channel_ids':null,'on_hold':null,'last_sla_comment':null,'location':null,'meta_data':{},'meter_readers':[],'collection_window':5,'memo':null},{'_id':'5825c85920fe9b0061547253','ean':'735999666123123123','name':null,'holder':{'_id':'5543677f37c6b65f008b46e4','name':'Example account','username':'someone@example.com'},'root':{'_id':'577fdd960c8a335c008b4669','holder':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','entity_type':'utility_provider'}},'assigner':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','username':'RobHarveyUtilityCompany-utility@example.com','manager':{'_id':null}},'created':'2016-11-11T13:32:09+0000','children':[],'address':'Gr\u00e4nsv\u00e4gen 12B','timezone':'Etc\/GMT-1','control_level':'shared','billing_category':'owned_meter_consumption','generation':1,'tags':[],'box':'active','revoked':false,'metrics':['energy'],'type':'electricity','consumption_stats':{'energy':{'month':{'count':45,'sum':141604.36,'max':6488.2,'last':201709,'min':1759.64,'first':201401},'hour':{'first':null,'last':null,'sum':null,'max':null,'min':null,'count':0},'day':{'first':null,'last':null,'sum':null,'max':null,'min':null,'count':0}}},'cost_stats':{},'readings_stats':null,'has_active_complaints':false,'representation':null,'open_channel_ids':null,'on_hold':null,'last_sla_comment':null,'location':null,'meta_data':{},'meter_readers':[],'collection_window':5,'memo':null},{'_id':'5825c85d22c8aa00606b9dd5','ean':'1200004','name':null,'holder':{'_id':'5543677f37c6b65f008b46e4','name':'Example account','username':'someone@example.com'},'root':{'_id':'577fdd960c8a335c008b466f','holder':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','entity_type':'utility_provider'}},'assigner':{'_id':'577fd0170c8a335c008b45fe','name':'Rob Harvey Utility Company','username':'RobHarveyUtilityCompany-utility@example.com','manager':{'_id':null}},'created':'2016-11-11T13:32:13+0000','children':[],'address':'Gr\u00e4nsv\u00e4gen 12B','timezone':'Etc\/GMT-1','control_level':'shared','billing_category':'owned_meter_consumption','generation':1,'tags':[],'box':'active','revoked':false,'metrics':['energy'],'type':'cooling','consumption_stats':{'energy':{'month':{'count':33,'sum':902350,'max':92560,'last':201709,'min':9730,'first':201501},'hour':{'first':null,'last':null,'sum':null,'max':null,'min':null,'count':0},'day':{'first':null,'last':null,'sum':null,'max':null,'min':null,'count':0}}},'cost_stats':{},'readings_stats':null,'has_active_complaints':false,'representation':null,'open_channel_ids':null,'on_hold':null,'last_sla_comment':null,'location':null,'meta_data':{},'meter_readers':[],'collection_window':5,'memo':null}]}";
var items = JsonConvert.DeserializeObject<ModelsClass.Rootobject>(json2);
foreach (ModelsClass.Rootobject value in items)
{
Console.WriteLine(value, items);
}
Console.ReadKey();
}
JsonConvert.DeserializeObject<ConsoleApplication2.Rootobject>(json2);
private static void printPropertyNameValue(object obj, int intent)
{
foreach (var property in obj.GetType().GetProperties())
{
if (!property.CanWrite)
continue;
var value = property.GetValue(obj);
if (value != null && value.GetType().IsArray)
{
Console.WriteLine("{0}{1}", "".PadLeft(intent, '-'), property.Name);
foreach (var item in ((Object[])value))
{
printPropertyNameValue(item, intent + 1);
}
}
else
{
if (value != null && (value.GetType()).IsClass)
{
Console.WriteLine("{0}{1}", "".PadLeft(intent, '-'), property.Name);
printPropertyNameValue(property.GetValue(obj), intent + 1);
}
else
{
Console.WriteLine("{0}{1}:{2}", "".PadLeft(intent, '-'), property.Name, value);
}
}
}
}
static void Main(string[] args)
{
string json2 = @"{""code"":200,""message"":""OK"",""profiling"":null,""count"":6,""skip"":0,""limit"":50,""next_page"":null,""previous_page"":null,""additional_meta"":{""and"":[{""deleted"":false},{""or"":[{""holder_id"":{""id"":""5543677f37c6b65f008b46e4""}},{""root.holder._id"":{""id"":""5543677f37c6b65f008b46e4""}}]}]},""data"":[{""_id"":""5825c6f6de22ae00632e86f3"",""ean"":""659842"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""5824790e3d214b006271c515"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:26:14+0000"",""children"":[],""address"":""Kungsgatan 2"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""heat"",""consumption_stats"":{""energy"":{""hour"":{""count"":26275,""sum"":6546140,""max"":930,""last"":2016123021,""min"":0,""first"":2014010101},""day"":{""count"":1091,""sum"":6522120,""max"":18900,""last"":20161229,""min"":1180,""first"":20140102},""month"":{""count"":33,""sum"":5727310,""max"":387190,""last"":201708,""min"":49750,""first"":201402}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c76920fe9b006308e412"",""ean"":""735999999564879216"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""5824790e3d214b006271c510"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:28:09+0000"",""children"":[],""address"":""Kungsgatan 2"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""electricity"",""consumption_stats"":{""energy"":{""hour"":{""count"":25953,""sum"":311714.628,""max"":34.3,""last"":2016121709,""min"":0,""first"":2014010101},""day"":{""count"":1080,""sum"":311302.328,""max"":689,""last"":20161216,""min"":141.1,""first"":20140102},""month"":{""count"":35,""sum"":306915.54,""max"":13704.72,""last"":201708,""min"":6013.932,""first"":201402}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c84b22c8aa00623d65a5"",""ean"":""6934363"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b4672"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:31:55+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""gas"",""consumption_stats"":{""energy"":{""month"":{""count"":24,""sum"":42656.62,""max"":8890.65,""last"":201708,""min"":104.57,""first"":201501},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c85320fe9b006308e41d"",""ean"":""5896584"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b466c"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:32:03+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""heat"",""consumption_stats"":{""energy"":{""month"":{""count"":57,""sum"":3592320,""max"":173000,""last"":201709,""min"":2000,""first"":201301},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c85920fe9b0061547253"",""ean"":""735999666123123123"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b4669"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:32:09+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""electricity"",""consumption_stats"":{""energy"":{""month"":{""count"":45,""sum"":141604.36,""max"":6488.2,""last"":201709,""min"":1759.64,""first"":201401},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null},{""_id"":""5825c85d22c8aa00606b9dd5"",""ean"":""1200004"",""name"":null,""holder"":{""_id"":""5543677f37c6b65f008b46e4"",""name"":""Example account"",""username"":""someone@example.com""},""root"":{""_id"":""577fdd960c8a335c008b466f"",""holder"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""entity_type"":""utility_provider""}},""assigner"":{""_id"":""577fd0170c8a335c008b45fe"",""name"":""Rob Harvey Utility Company"",""username"":""RobHarveyUtilityCompany-utility@example.com"",""manager"":{""_id"":null}},""created"":""2016-11-11T13:32:13+0000"",""children"":[],""address"":""Gr\u00e4nsv\u00e4gen 12B"",""timezone"":""Etc\/GMT-1"",""control_level"":""shared"",""billing_category"":""owned_meter_consumption"",""generation"":1,""tags"":[],""box"":""active"",""revoked"":false,""metrics"":[""energy""],""type"":""cooling"",""consumption_stats"":{""energy"":{""month"":{""count"":33,""sum"":902350,""max"":92560,""last"":201709,""min"":9730,""first"":201501},""hour"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0},""day"":{""first"":null,""last"":null,""sum"":null,""max"":null,""min"":null,""count"":0}}},""cost_stats"":{},""readings_stats"":null,""has_active_complaints"":false,""representation"":null,""open_channel_ids"":null,""on_hold"":null,""last_sla_comment"":null,""location"":null,""meta_data"":{},""meter_readers"":[],""collection_window"":5,""memo"":null}]}";
var items = JsonConvert.DeserializeObject<ConsoleApplication2.Rootobject>(json2);
printPropertyNameValue(items, 0);
Console.ReadKey();
}