简体   繁体   English

与JSON.NET一起使用的类

[英]Classes to use with JSON.NET

I can't seem to wrap my head around JSON in C#. 我似乎无法将C#中的JSON包裹住。 I use JSON.NET and usually I can figure out the class needed to convert. 我使用JSON.NET,通常我可以找出转换所需的类。 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. 说,我对result对感兴趣。 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 ? 我将如何映射列表(2.0、3.0、4.0、5.0)的值及其封闭result

Not sure at all... 完全不确定...

Currency is a list of lists of double. 货币是重复列表的列表。 Your Result object should look something like: 您的Result对象应类似于:

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. 此外,Visual Studio在“编辑”菜单下具有“选择性粘贴”选项,该选项可用于将剪贴板中的XML或JSON字符串转换为符合该结构的C#类。

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. 为了避免发生错误的可能性,您可以这样操作:复制JSON文件,然后转到Visual Studio => Edit => Paste Special => Paste JSON as class。 This will generate the classes for you. 这将为您生成类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM