Keyboard Shortcuts
ctrl + shift + ? :
Show all keyboard shortcuts
ctrl + g :
Navigate to a group
ctrl + shift + f :
Find
ctrl + / :
Quick actions
esc to dismiss
Likes
Search
NewtonSoft Problem
I'm trying to convert some JSON into a series of C# classes.? My problem is that one of the classes is named Event and this is causing a conflict with SimplWindows because that name is already used.? I know that NewtonSoft allows you to use JsonProperty to perform a renaming of an element of a class to avoid a similar conflict but I can't find anything that will solve this problem for a class.
ERROR? (LGSPLS1000)?? 'Event' already defined ??? public class Root ??? { ??????? public int id { get; set; } ??????? public string type { get; set; } ??????? public Event @event { get; set; } ??? } ??? public class Event ??? { ??????? public string event_type { get; set; } ??????? public DateTime time_fired { get; set; } ??????? public string origin { get; set; } ??? } Thanks in advance for the help Jay |
If you are deserializing to a typed object your class name does not have to match anything within the json.? Can you make it something other than "Event" and then make sure the property name matches with your json string.? Something like the following ? public class Root ???? { ???????? public int id { get; set; } ???????? public string type { get; set; } ???????? public EventItem event { get; set; } ???? } ???? public class EventItem ???? { ???????? public string event_type { get; set; } ???????? public DateTime time_fired { get; set; } ???????? public string origin { get; set; } ???? } On Thu, May 15, 2025, 7:22?PM jbasen via <jay.m.basen=[email protected]> wrote: I'm trying to convert some JSON into a series of C# classes.? My problem |
¿ªÔÆÌåÓýThanks so much Jordan.? Because NewtonSoft is matching up names I thought I had to use something similar to the JsonProperty directive.? However, you are absolutely correct.? This works perfectly. Thanks again Jay On 5/15/2025 5:38 PM, Jordan Elasky via
groups.io wrote:
|
¿ªÔÆÌåÓýThanks Oliver.? The first thing I tried was using a JsonProperty statement but I couldn't get it to work.? Fortunately, just changing the class name did. Thanks Jay On 5/16/2025 2:06 AM, Oliver Hall via
groups.io wrote:
|
to navigate to use esc to dismiss