Click here to Skip to main content
14,550,580 members
Rate this:
Please Sign up or sign in to vote.
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

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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100