我需要在c#中反序列化blow JSON数据到类列表。它包含动态数据Egg:MACHINE和MACHINE2,以及SAP数据数组1和2和3是动态数据,如果任何一个引导我到达一个输出,然后要将数据存储到数据库
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:41","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":"0","Program Name":"-","Part Count":"45916","alarmData":[],"Power on Time":"31822844","Running Time":"18366222","Breakdown Time":"1","Idle Time":"13352656"},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]},
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:36","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":0,"Program Name":"-","Part Count":1,"alarmData":[],"Power on Time":1,"Running Time":1,"Breakdown Time":1,"Idle Time":1},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]
},
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:36","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":0,"Program Name":"-","Part Count":1,"alarmData":[],"Power on Time":1,"Running Time":1,"Breakdown Time":1,"Idle Time":1},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]
},
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:36","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":0,"Program Name":"-","Part Count":1,"alarmData":[],"Power on Time":1,"Running Time":1,"Breakdown Time":1,"Idle Time":1},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]
},
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:36","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":0,"Program Name":"-","Part Count":1,"alarmData":[],"Power on Time":1,"Running Time":1,"Breakdown Time":1,"Idle Time":1},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]
}
]
},
{"MACHINE2":[
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:41","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":"0","Program Name":"-","Part Count":"45916","alarmData":[],"Power on Time":"31822844","Running Time":"18366222","Breakdown Time":"1","Idle Time":"13352656"},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]},
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:36","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":0,"Program Name":"-","Part Count":1,"alarmData":[],"Power on Time":1,"Running Time":1,"Breakdown Time":1,"Idle Time":1},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]
},
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:36","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":0,"Program Name":"-","Part Count":1,"alarmData":[],"Power on Time":1,"Running Time":1,"Breakdown Time":1,"Idle Time":1},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]
},
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:36","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":0,"Program Name":"-","Part Count":1,"alarmData":[],"Power on Time":1,"Running Time":1,"Breakdown Time":1,"Idle Time":1},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]
},
{"Live Machine Data":{"Date":"31-03-2023","Time":"09:16:36","IP Number":"-","Machine Number":"VMC-03","Machine Name":"VMC003","Machine Status":0,"Program Name":"-","Part Count":1,"alarmData":[],"Power on Time":1,"Running Time":1,"Breakdown Time":1,"Idle Time":1},
"SAP Data":[
{"1":{"Client ID":"555","Order Number":"11186324","Order Quantity":3,"Material Code":"123","Produced Quantity":0}},
{"2":{"Client ID":"555","Order Number":"11186325","Order Quantity":4,"Material Code":"123","Produced Quantity":0}},
{"3":{"Client ID":"555","Order Number":"11186326","Order Quantity":5,"Material Code":"123","Produced Quantity":0}}]
}]}]
要存储到数据库
1条答案
按热度按时间ghhkc1vu1#
使用下面的代码:
首先定义相应的模型:
最后使用以下代码进行反序列化: