I have a JSON string. which has a part like this
"Result": {
"AdditionalInfo": {
"SubCategoryID": "978",
"SellerPartNumber": "04-VO7T-14PP",
"ManufacturerPartNumberOrISBN": "04-VO7T-14PP",
"UPC": null
},
"ErrorList": {
"ErrorDescription": [
{
"#cdata-section": "Error(s). Item not created."
},
{
"#cdata-section": "Error:[Item does not exist. Please create a new list.]"
}
]
}
}
However, sometimes that part is an array as well. like
"Result": [
{
"AdditionalInfo": {
"SubCategoryID": "1512",
"SellerPartNumber": "TY-SZT1-358V",
"ManufacturerPartNumberOrISBN": "TY-SZT1-358V",
"UPC": null
},
"ErrorList": {
"ErrorDescription": [
{
"cdata-section": "Error(s). Item not created."
},
{
"cdata-section": "CufflinkMaterial - Property: [CufflinkMaterial] value error. The submitted value: [MPS.Domain.SubCategoryProperty] is not recognized for this property."
},
{
"cdata-section": "CufflinkType - Property: [CufflinkType] value error. The submitted value: [MPS.Domain.SubCategoryProperty] is not recognized for this property."
}
]
}
},
{
"AdditionalInfo": {
"SubCategoryID": "1512",
"SellerPartNumber": "UF-T05C-T6XG",
"ManufacturerPartNumberOrISBN": "UF-T05C-T6XG",
"UPC": null
},
"ErrorList": {
"ErrorDescription": [
{
"cdata-section": "Error(s). Item not created."
},
{
"cdata-section": "CufflinkMaterial - Property: [CufflinkMaterial] value error. The submitted value: [MPS.Domain.SubCategoryProperty] is not recognized for this property."
},
{
"cdata-section": "CufflinkType - Property: [CufflinkType] value error. The submitted value: [MPS.Domain.SubCategoryProperty] is not recognized for this property."
}
]
}
},
{
"AdditionalInfo": {
"SubCategoryID": "1512",
"SellerPartNumber": "5B-1137-WT3O",
"ManufacturerPartNumberOrISBN": "5B-1137-WT3O",
"UPC": null
},
"ErrorList": {
"ErrorDescription": [
{
"cdata-section": "Error(s). Item not created."
},
{
"cdata-section": "CufflinkMaterial - Property: [CufflinkMaterial] value error. The submitted value: [MPS.Domain.SubCategoryProperty] is not recognized for this property."
},
{
"cdata-section": "CufflinkType - Property: [CufflinkType] value error. The submitted value: [MPS.Domain.SubCategoryProperty] is not recognized for this property."
}
]
}
}
]
Is there a generic way that I can Deserlize both JSON without defining different objects? So like, I define an array of Result object, and when there is single entity, it will create one index in the object array, and when there are multiple, it may create multiple indexes in the array.
Ultimate goal is to use object object and use that to parse both single Result object or multiple.
Is that something possible? thanks Sameers