• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c#多层JSON数据动态解析

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.json数据

{
    "workOrderId": "WW0000001-01-01",
    "orderDate": "2020-01-01",
    "productNum": "1",
    "productId": "P1205000900",
    "productModel": "TRD-271000AF",
    "planModel": "P",
    "productSimpleCode": "P1205",
    "productQuantity": 100,
    "workshop": "",
    "workCore": "",
    "procedure": [{
            "orderId": "PG0001",
            "procedureId": "01",
            "procedureName": "插件焊接",
            "id": 1,
            "materialInfo": [{
                "materialId": "C001",
                "positionNum": "",
                "trayCode": "tp001-1",
                "singleUse": "1",
                "materialUse": "100"
            }, {
                "materialId": "C002",
                "positionNum": "",
                "trayCode": "tp001-2",
                "singleUse": "2",
                "materialUse": "50"
            }]
        }, {
            "orderId": "PG0002",
            "procedureId": "02",
            "procedureName": "LED安装",
            "id": 2,
            "materialInfo": [{
                "materialId": "C003",
                "positionNum": "",
                "trayCode": "tp002-1",
                "singleUse": "1",
                "materialUse": "100"
            }, {
                "materialId": "C004",
                "positionNum": "",
                "trayCode": "tp002-2",
                "singleUse": "2",
                "materialUse": "50"
            }]
        }, {
            "orderId": "PG0003",
            "procedureId": "03",
            "procedureName": "光栅贴附",
            "id": 3,
            "materialInfo": [{
                "materialId": "C004",
                "positionNum": "",
                "trayCode": "tp003-1",
                "singleUse": "1",
                "materialUse": "100"
            }, {
                "materialId": "C005",
                "positionNum": "",
                "trayCode": "tp003-2",
                "singleUse": "2",
                "materialUse": "50"
            }]
        }]
}

 

2.json对象创建(注:对象名称必须与json数据名称保持一致)

using System.Collections.Generic;

namespace Global
{
    public class WorkOrderReceived
    {
        public string workOrderId { get; set; }

        public string orderDate { get; set; }

        public string productNum { get; set; }

        public string productId { get; set; }

        public string productModel { get; set; }

        public string planModel { get; set; }

        public string productSimpleCode { get; set; }

        public string productQuantity { get; set; }

        public string workshop { get; set; }

        public string workCore { get; set; }

        public List<procedure> procedure { get; set; }

    }

    public class procedure
    {
        public string orderId { get; set; }

        public string procedureId { get; set; }

        public string procedureName { get; set; }

        public string id { get; set; }

        public List<materialInfo> materialInfo { get; set; } 
    }

    public class materialInfo
    {
        public string materialId { get; set; }

        public string positionNum { get; set; }

        public string trayCode { get; set; }

        public string singleUse { get; set; }

        public string materialUse { get; set; }
    }
}

3.解析代码

using Newtonsoft.Json;   
、
 public void AnaysisJson(string jsonValue)
 {
     WorkOrderReceived workOrderReceived = JsonConvert.DeserializeObject<WorkOrderReceived>(jsonValue); 
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C语言绘制表格发布时间:2022-07-13
下一篇:
C#文件读写常用类介绍发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap