Click here to Skip to main content
15,895,813 members

What is the exact C# classes that matched with the below json?

evilsoull asked:

Open original thread
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
Tags: C#, JSON

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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