Hi,
I need to deserialize the blow json data to class list in c#.
[
{
"M1": [
{
"Machine Data": {
"Date": "20-02-2023",
"Time": "09:16:41",
"IP Number": "-",
"Machine Number": "M1",
"Machine Name": "M1",
"Machine Status": "0",
"Program Name": "-",
"Part Count": "1",
"Power on Time": "1",
"Running Time": "1",
"Breakdown Time": "1",
"Idle Time": "1"
},
"SP Data": [
{
"Orders": {
"Client ID": "1",
"Order Number": "123",
"Order Quantity": "3",
"Material Code": "123",
"Produced Quantity": "1"
}
},
{
"Orders": {
"Client ID": "2",
"Order Number": "1234",
"Order Quantity": "4",
"Material Code": "123",
"Produced Quantity": "2"
}
},
{
"Orders": {
"Client ID": "2",
"Order Number": "1234",
"Order Quantity": "4",
"Material Code": "123",
"Produced Quantity": "2"
}
}
]
}
]
}
]
Jaya PrakashPosted Mar 31, 2023, 10:16 AM
pls modify according to ur req
for encryption
for decryption json
Jignesh KumarPosted Mar 31, 2023, 9:29 AM
Hello Maniknandan,
If you are gettting response as dynamic then you can try this one,
Rajkiran SwainPosted Mar 31, 2023, 7:38 AM
If the "M1" property is dynamic and may have different values in the JSON, you can define the property as a dictionary with string keys and a value of type
Listlike this:Then you can deserialize the JSON string into a
Listobject like this:This will give you a list of
Rootobjects, each with aDictionary> property calledMachines. The key of the dictionary will be the dynamic property name (e.g. "M1"), and the value will be a list ofMachineobjects with the corresponding data.Manikandan RPosted Mar 31, 2023, 7:34 AM
Thanks for the reply, have another problem inthe top of the json M1 is a dynamic data, how will arraive with class Property
Rajkiran SwainPosted Mar 31, 2023, 6:36 AM
Jignesh KumarPosted Mar 31, 2023, 6:02 AM
Hello,
Try below one,
While deserialization use below one,