Reputation:
I can't seem to wrap my head around JSON
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 result
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 result
?
Not sure at all...
Upvotes: 0
Views: 61
Reputation: 9704
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.
Upvotes: 1
Reputation: 985
To avoid any probability of errors, you can do like this: copy your JSON file, go to Visual Studio=>Edit=>Paste Special=>Paste JSON as class. This will generate the classes for you.
Upvotes: 1