Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below json and C# class does not match because there are two json objects named same "Event". I am getting null from the second "Event" object. I could not find the matched C# class. What am I doing wrong?


This is json
{
  "Sequence": 1802487,
  "BusinessDate": "2020-05-17T00:00:00.0000000",
  "Event": {
    "Event": {
      "@RegId": "2269"
	  }
  }
}


and this is the C# classes that I am using for deserializing

C#
public class Root
{
    public long Sequence { get; set; }
    public DateTime BusinessDate { get; set; }

    [JsonProperty("Event")]
    public Event1 Event { get; set; }
}

[JsonObject("Event")]
public class Event1
{
    public Event Event { get; set; }
}

public class Event
{
    [JsonProperty("@RegId")]
    public string RegId { get; set; }
}


What I have tried:

Because of there are two "Event" json objects, I had to change the one of the class names as "Event1". But I am getting null for RegId
Posted
Comments
F-ES Sitecore 23-May-20 9:47am    
Your code works fine for me, how are you deserialising it?
evilsoull 23-May-20 12:14pm    
Yes you are right, I tried to deserialize by using Newtonsoft.JsonConvert and it worked fine. I am working on RavenDB and deserializing is done by it automatically. So I figured out that there is a problem with RavenDB deserializing process. Thank you for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900