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

Solution 1

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.
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Json.NET[^] may also be useful.
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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[^]
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Since all of the messages seem to share a common set of properties, try something like this:
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; }
}
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Copy your json string to the clipboard and then from the edit menu in visual studio choose paste special.
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190524.3 | Last Updated 16 May 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100