Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
{ "Description": "This registry defines the events for the management processor.",
"Id": "Events.json",
"Messages": {
"AEPSecureEraseFailed": {
"Description": "Secure Erase of Intel Optane DC Persistent Memory has failed.",
"Message": "Secure Erase of Intel Optane DC Persistent Memory has failed",
"ParamTypes": ["string", "string", "string"],
"Resolution": "Retry Secure Erase. Please contact HPE Support if issue persists.",
"Severity": "Critical"
},
"AdapterConfigurationChange": {
"Description": "The specified adapter has had a configuration change.",
"Message": "The adapter in slot %1 has had a configuration change.",
"Resolution": "None",
"Severity": "Ok"
},
"FanRemoved": {
"Description": "The fan is removed.",
"Message": "The fan is removed.",
"Resolution": "None",
"Severity": "Warning"
}
},
"Name": "Event Registry"
}

What I have tried:

public class AEPSecureEraseFailed
{
public string Description { get; set; }
public string Message { get; set; }
public List<string> ParamTypes { get; set; }
public string Resolution { get; set; }
public string Severity { get; set; }
}

public class AdapterConfigurationChange
{
public string Description { get; set; }
public string Message { get; set; }
public string Resolution { get; set; }
public string Severity { get; set; }
}

public class FanRemoved
{
public string Description { get; set; }
public string Message { get; set; }
public string Resolution { get; set; }
public string Severity { get; set; }
}

public class Messages
{
public AEPSecureEraseFailed AEPSecureEraseFailed { get; set; }
public AdapterConfigurationChange AdapterConfigurationChange { get; set; }
public FanRemoved FanRemoved { get; set; }
}

public class RootObject
{
public string Description { get; set; }
public string Id { get; set; }
public Messages Messages { get; set; }
public string Name { get; set; }
}

Is there any other way of deserialising other than:
public class Messages
{
public AEPSecureEraseFailed AEPSecureEraseFailed { get; set; }
public AdapterConfigurationChange AdapterConfigurationChange { get; set; }
public FanRemoved FanRemoved { get; set; }
}
so that we do not have to write the same lines for the other 256 left events
Posted
Updated 16-May-19 4:36am

I would like to recommend
json2csharp - generate c# classes from json[^]
This site will generate a C# class from any valid JSON string.
There is no need to write a corresponding C# class by hand.
 
Share this answer
 
Json.NET[^] may also be useful.
 
Share this answer
 
As you're starting out with serialization of JSON data, this article answers this question and many others that you will have: Working with JSON in C# & VB[^]
 
Share this answer
 
Since all of the messages seem to share a common set of properties, try something like this:
C#
public class ErrorMessage
{
    public string Description { get; set; }
    public string Message { get; set; }
    public string Resolution { get; set; }
    public string Severity { get; set; }
    
    // Add any other interesting properties from the different messages here.
    // Any which are not available for this message will be null.
    public List<string> ParamTypes { get; set; }
}

public class RootObject
{
    public string Description { get; set; }
    public string Id { get; set; }
    public string Name { get; set; }
    public Dictionary<string, ErrorMessage> Messages { get; set; }
}
 
Share this answer
 
Copy your json string to the clipboard and then from the edit menu in visual studio choose paste special.
 
Share this answer
 
Comments
phil.o 15-May-19 9:05am    
This is a design-time operation. OP's requirements seem to happen at run-time.
RmcbainTheThird 15-May-19 12:56pm    
Oops gotta learn to read gooder

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