user1144596
user1144596

Reputation: 2088

C# to JSON conversion, dictionary

I have a class as follows and I want its JSON signature. It's the last property Actions that I am unsure about how to transfer to JSON. I have tried C# to JSON converter online but it gives null for Actions.

 public class Notification
    {
        public string Name { get; set; }
        public string Body { get; set; }
        public string Subject { get; set; }
        public string Users { get; set; }
        public string Date { get; set; }
        public List<Dictionary<string,Dictionary<string,string>>> Action { get; set; }
    }

Any help here would be most appreciated.

Upvotes: 1

Views: 84

Answers (1)

Ezequiel Jadib
Ezequiel Jadib

Reputation: 14787

The json for that class would be:

{  
   "Name":"Test",
   "Body":"TestBody",
   "Subject":"TestSubject",
   "Users":"TestUsers",
   "Date":"9/22/2016 12:26:20 PM",
   "Action":[  
      {  
         "key":{  
            "innerKey":"value"
         }
      }
   ]
}

for this C# code:

var notification = new Notification()
{
    Name = "Test",
    Body = "TestBody",
    Subject = "TestSubject",
    Users = "TestUsers",
    Date = DateTime.Now.ToString(),
    Action = new List<Dictionary<string, Dictionary<string, string>>>()
    {
        new Dictionary<string, Dictionary<string, string>>()
        {
            { "key", new Dictionary<string, string>() { { "innerKey", "value" } } }
        }
    }
};

Upvotes: 1

Related Questions