我必须为所需的JSON结构构建一个模型类 [英] I have to construct a model class for the desired JSON structure

查看:35
本文介绍了我必须为所需的JSON结构构建一个模型类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Obj1:{
0:17,
1:23,
2:23,
3:24,
4:25,
5:56,
6:65
},
Obj2:{0:177,..,6:65},
Obj3:{0:177,..,6:65},
Obj4:{0:177,..,6:65}



任何人都可以帮助我生成Modal类的最佳方法吗?我正在使用POCO反向生成方法来获取数据。所以大多数情况下我会使用LINQ映射到Modal类。



我尝试过:

< br $>

公共类周
{
public int?[] Obj1 = new int?[6];

public int?[] Obj2 = new int?[6];

public int?[] Obj3 = new int?[6];

public int?[] Obj4 = new int?[6];
}

解决方案

您可以使用此服务从有效的JSON数据生成类:JSON Utils:从JSON生成C#,VB.Net,SQL表,Java和PHP [ ^ ]



您的JSON数据无效。看着你的课,它应该是这样的:

 {Obj1:[
17,
23,
23 ,
24,
25,
56,
$ 65
],
Obj2:[177,...,65],
Obj3:[177,...,65],
Obj4:[177,...,65]
}



您可以在这里阅读更多内容:在C#中使用JSON& VB [ ^ ]


"Obj1": {
      0: 17, 
      1: 23,
      2: 23, 
      3: 24,
      4: 25,
      5: 56,
      6: 65
    },
    "Obj2": {0: 177,..,6: 65},      
    "Obj3": {0: 177,..,6: 65},
    "Obj4": {0: 177,..,6: 65}


Can anyone help me the best way to generate the Modal class? I am using POCO reverse generation method to fetch the data. So mostly I will be using LINQ to map into Modal class.

What I have tried:

public class Week
    {
        public int?[] Obj1= new int?[6];

        public int?[] Obj2= new int?[6];

        public int?[] Obj3= new int?[6];

        public int?[] Obj4= new int?[6];
    }

解决方案

You can use this service for generating classes from valid JSON data: JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^]

Your JSON data is invalid. Looking at your class, it should be something like:

{"Obj1": [
      17, 
      23,
      23, 
      24,
      25,
      56,
      65
    ],
    "Obj2": [177,...,65],
    "Obj3": [177,...,65],
    "Obj4": [177,...,65]
}


You can read more here: Working with JSON in C# & VB[^]


这篇关于我必须为所需的JSON结构构建一个模型类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆