https://stackoverflow.com/questions/48167689

CSharp · Console

/Program.cs

using System;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
					
public class Program
{
	public static void Main()
	{
		string json = @"
            {
              ""[email protected]"": {
                ""time"": ""2018-01-02T20:45:46.65Z"",
                ""type"": ""Complaint"",
                ""bounceType"": ""null"",
                ""bounceSubType"": ""null""
              },
              ""[email protected]"": {
                ""time"": ""2018-01-02T20:53:03Z"",
                ""type"": ""Bounce"",
                ""bounceType"": ""Permanent"",
                ""bounceSubType"": ""Suppressed""
              },
              ""[email protected]"": {
                ""time"": ""2018-01-02T21:06:40.097Z"",
                ""type"": ""Bounce"",
                ""bounceType"": ""Permanent"",
                ""bounceSubType"": ""Suppressed""
              },
              ""[email protected]"": {
                ""time"": ""2018-01-02T21:08:02Z"",
                ""type"": ""Bounce"",
                ""bounceType"": ""Permanent"",
                ""bounceSubType"": ""General""
              },
              ""[email protected]"": {
                ""time"": ""2018-01-05T06:31:39Z"",
                ""type"": ""Bounce"",
                ""bounceType"": ""Permanent"",
                ""bounceSubType"": ""General""
              },
              ""[email protected]"": {
                ""time"": ""2018-01-05T06:49:13Z"",
                ""type"": ""Bounce"",
                ""bounceType"": ""Permanent"",
                ""bounceSubType"": ""Suppressed""
              },
              ""[email protected]"": {
                ""time"": ""2018-01-07T12:50:38Z"",
                ""type"": ""Bounce"",
                ""bounceType"": ""Transient"",
                ""bounceSubType"": ""General""
              },
              ""[email protected]"": {
                ""time"": ""2018-01-02T08:12:19Z"",
                ""type"": ""Bounce"",
                ""bounceType"": ""Transient"",
                ""bounceSubType"": ""MailboxFull""
              },
              ""[email protected]"": {
                ""time"": ""2018-01-05T07:00:24Z"",
                ""type"": ""Complaint"",
                ""bounceType"": ""null"",
                ""bounceSubType"": ""null""
              }
            }";
		
		var dict = JsonConvert.DeserializeObject<Dictionary<string, BounceItem>>(json);
		
		var list = dict.Select(kvp => { kvp.Value.Email = kvp.Key; return kvp.Value; }).ToList();
		
		
		string format = "{0,-35} {1,-22} {2,-10} {3,-11} {4}";
		Console.WriteLine(string.Format(format, "Email", "Time", "Type", "BounceType", "BounceSubType"));
		Console.WriteLine(string.Format(format, new String('-',35), new String('-',22), new String('-',10), new String('-',11), new String('-',13)));
		
		foreach (var item in list)
		{
			Console.WriteLine(string.Format(format, item.Email, item.Time, item.Type, item.BounceType, item.BounceSubType));
		}
		
	}
}

class BounceItem
{
	public string Email { get; set; }
	public DateTime Time { get; set; }
	public string Type { get; set; }
	public string BounceType { get; set; }
	public string BounceSubType { get; set; }
}
;