zoukankan      html  css  js  c++  java
  • c# 多层JSON数据动态解析

    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); 
    }
  • 相关阅读:
    UVa 1643 Angle and Squares
    UVa 1210 (高效算法设计) Sum of Consecutive Prime Numbers
    UVa 1213 (01背包变形) Sum of Different Primes
    UVa 1644 (筛素数 + 二分) Prime Gap
    UVa 10048 (Floyd变形) Audiophobia
    UVa 247 (传递闭包) Calling Circles
    UVa 808 (建坐标系、找规律) Bee Breeding
    UVa 1151 (枚举 + MST) Buy or Build
    UVa 1395 (最小生成树) Slim Span
    UVa 11040 (水题) Add bricks in the wall
  • 原文地址:https://www.cnblogs.com/hanglog/p/13743268.html
Copyright © 2011-2022 走看看