Skip to content

JSON to CSharp Class in Visual studo

Method to convert json object to class identical to json object,

  1. Copy json String. for example go to link http://json.org/example.html and compy any json string
    {
    "glossary": {
    "title": "example glossary",
    "GlossDiv": {
    "title": "S",
    "GlossList": {
    "GlossEntry": {
    "ID": "SGML",
    "SortAs": "SGML",
    "GlossTerm": "Standard Generalized Markup Language",
    "Acronym": "SGML",
    "Abbrev": "ISO 8879:1986",
    "GlossDef": {
    "para": "A meta-markup language, used to create markup languages such as DocBook.",
    "GlossSeeAlso": ["GML", "XML"]
    },
    "GlossSee": "markup"
    }
    }
    }
    }
    }
  2. Open visual studio and one .cs file 2BlankClass
  3. Go to edit menu and select paste special and click on Paste Json as Classes.3pastejsonasclasses
  4. You can find complete identical Class of json as .
    public class Rootobject
    {
    public Glossary glossary { get; set; }
    }
    
    public class Glossary
    {
    public string title { get; set; }
    public Glossdiv GlossDiv { get; set; }
    }
    
    public class Glossdiv
    {
    public string title { get; set; }
    public Glosslist GlossList { get; set; }
    }
    
    public class Glosslist
    {
    public Glossentry GlossEntry { get; set; }
    }
    
    public class Glossentry
    {
    public string ID { get; set; }
    public string SortAs { get; set; }
    public string GlossTerm { get; set; }
    public string Acronym { get; set; }
    public string Abbrev { get; set; }
    public Glossdef GlossDef { get; set; }
    public string GlossSee { get; set; }
    }
    
    public class Glossdef
    {
    public string para { get; set; }
    public string[] GlossSeeAlso { get; set; }
    }
    
    

Leave a Reply

%d bloggers like this: