I have a Web API method to mapping a Json array to C# object.
My parameter should be like the following:
[{"event":"inbound","msg":"TestMEssage","ts":123456}]
and my code is
var events = JsonConvert.DeserializeObject<IEnumerable<MailEvent>>(mandrill_inbound);
public class MailEvent
{
[JsonProperty(PropertyName = "event")]
public string Event { get; set; }
[JsonProperty(PropertyName = "msg")]
public string Msg { get; set; }
[JsonProperty(PropertyName = "ts")]
public string TimeStamp { get; set; }
}
But when am trying to Deserialize the JSON it's showing exception.
But If I am trying to set a variable inside the method like
Public const string mandrill_inbound = @"[
{
""event"": ""inbound"",
""msg"": ""tewst"",
""ts"": 1368214102
},
{
""event"": ""inbound"",
""msg"": ""test2"",
""ts"": 1368214102
}
]";
This code will be working perfectly for me.
Noting that it has starting with @"" and all the key values are surrounded with multiple Double quotes(""event"").
Actually what is the difference between these two formats.
Any help will be appreciated.