Alexej Alexej - 1 year ago 69
JSON Question

Classes to use with JSON.NET

I can't seem to wrap my head around

in C#. I use JSON.NET and usually I can figure out the class needed to convert. However in this case it's challenging: there is no name for the individual list items.

{"error":[], "result":{"currency":[[2.0, 3.0, 4.0, 5.0], [6.0, 7.0, 8.0, 9.0], ... ]}}

This is an example from memory, I hope the syntax is right.

So, when I attempt to create the classes, I don't know where to start. Say, I am interested in the
pair. Is "currency" a list of lists? How would I map the value for the list (2.0, 3.0, 4.0, 5.0) and its enclosing

Not sure at all...

Answer Source

Currency is a list of lists of double. Your Result object should look something like:

public class Result {
    List<List<double>> Currency {get;set;}

Additionally, Visual Studio has a 'Paste Special' option under the Edit Menu that can be used to turn an XML or JSON string from the clipboard into C# classes that conform to the structure.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download