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); 
    }
  • 相关阅读:
    项目开发中需要注意的
    数据库函数
    C#中 ?. 运算符
    字符串格式化String.Format
    day37 进程理论 多进程
    36 网络编程---操作系统 并发
    day35 socket的常用方法,
    day34
    day33天 网络编程udp pycharm控制台输出带颜色
    day32 网络编程初识
  • 原文地址:https://www.cnblogs.com/hanglog/p/13743268.html
Copyright © 2011-2022 走看看