locked
how to create poko class for JObject Data RRS feed

  • Question

  • User459073359 posted

    Title 1

             Key : Value 

             Key :  Value 

    Title 2

             Key :  Value 

             Key : Value 

    Title 3

            Key : Value 

            Key : Value 

    Monday, August 19, 2019 3:54 PM

All replies

  • User-2054057000 posted

    You can use http://json2csharp.com/ to create a C# class in seconds based on your json. Once you have the json class you can fill it with values from json using Newtonsoft dll. 

    You can see this tutorial where json values are extracted quite easily.

    Monday, August 19, 2019 4:14 PM
  • User-474980206 posted

    it looks like mapped data (collections of collections). would need to see sample of actual json.

    Monday, August 19, 2019 4:33 PM
  • User459073359 posted
    data = "{\"example1.com\":{\"classkey\":\"domcno\",\"status\":\"regthroughus\"},\"example2.com\":{\"classkey\":\"domcno\",\"status\":\"available\"},\"example3.com\":{\"classkey\":\"domcno\",\"status\":\"available\"}}"
    Monday, August 19, 2019 4:38 PM
  • User459073359 posted
    data = "{\"example1.com\":{\"classkey\":\"domcno\",\"status\":\"regthroughus\"},\"example2.com\":{\"classkey\":\"domcno\",\"status\":\"available\"},\"example3.com\":{\"classkey\":\"domcno\",\"status\":\"available\"}}"




    How to make class for this type of data
    Monday, August 19, 2019 4:39 PM
  • User-474980206 posted

    simple:

    public class MyItems
    {
       public string classkey {get; set;}
       public string status {get; set;}
    }
    
    ...
    
    var data = "{\"example1.com\":{\"classkey\":\"domcno\",\"status\":\"regthroughus\"},\"example2.com\":{\"classkey\":\"domcno\",\"status\":\"available\"},\"example3.com\":{\"classkey\":\"domcno\",\"status\":\"available\"}}";
    
    var poco = JsonConvert.DeserializeObject<Dictionary<string, MyItems>>(data);
    
    Console.WriteLine(poco["example1.com"].classkey);
    

    Monday, August 19, 2019 10:25 PM
  • User-2054057000 posted

    data = "{\"example1.com\":{\"classkey\":\"domcno\",\"status\":\"regthroughus\"},\"example2.com\":{\"classkey\":\"domcno\",\"status\":\"available\"},\"example3.com\":{\"classkey\":\"domcno\",\"status\":\"available\"}}"




    How to make class for this type of data

    It will be:

    public class jSamp
    {
        public string classkey { get; set; }
        public string status { get; set; }
    }

    Tuesday, August 20, 2019 5:14 AM