Announcement

Collapse
No announcement yet.

JSON conversion question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSON conversion question

    Hello All,

    I have just really started to learn the joys of JSON, and have been really enjoying the ease of sending structured data using JSON strings.

    My issue now however is how to most efficiently handle JSON strings in my program, basically I have a number of classes which specify different members or properties, and once I recieve a JSON string I do something like the below to convert the string into a usable object:

    Dim obj = JsonConvert.DeserializeObject(json class info)(...your_json...)

    My question is this though, I have been doing the above with different classes, and going that way, but I thought it would be more efficient to have one class with maybe subclasses

    so say for example my json string had the following parameters and I had another string where just some of the parameters changed

    method, version, status, apikey, parameter 1, parameter 2, parameter 3

    I then thought it might be better to take the parameter 1, 2 and 3 out and have the class be method, version, status, apikey, data where data is a nested JSON string which changes based on the method.

    What I am unsure about, is how to define that class. I can't have a static class which defines parameter 1, 2 and 3 because with another method it might have names parameter 4, 5 and 5.

    Is there a better way to do this, or should I just have different classes which repeat properties?

    Many Thanks
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

  • #2
    Look up Generics. Sounds like a generic parameter type is what you need.

    Comment


    • #3
      Thank you!
      HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

      Facebook | Twitter | Flickr | Google+ | Website | YouTube

      Comment

      Working...
      X