I have a JSON Response that sometimes returns an array when there are more than 1 elements and just an object when there is only one element.
Something Like this:-
"JLLBrokerAllocations": {
"JLLBrokerAllocation": [
{
"AllocPercent": 50,
"Amount": 4,
"Email": "",
"EmpId": 214309,
"EmpLoginId": "Carlin.Power",
"EmpName": "Power, Carlin",
"Id": 1147842,
"LeadBroker": true,
"MarketId": "AM0001",
"Markets": "",
"OpUnitId": 250050,
"OpUnits": ""
},
{
"AllocPercent": 50,
"Amount": 4,
"Email": "",
"EmpId": 999111,
"EmpLoginId": "Sai.Abhiram",
"EmpName": "Abhiram, Sai",
"Id": 1147843,
"LeadBroker": true,
"MarketId": "AM2900",
"Markets": "",
"OpUnitId": 200028,
"OpUnits": ""
}
]
},
Sometimes Like this:-
"JLLBrokerAllocations": {
"JLLBrokerAllocation":
{
"AllocPercent": 50,
"Amount": 4,
"Email": "",
"EmpId": 214309,
"EmpLoginId": "Carlin.Power",
"EmpName": "Power, Carlin",
"Id": 1147842,
"LeadBroker": true,
"MarketId": "AM0001",
"Markets": "",
"OpUnitId": 250050,
"OpUnits": ""
}
}
The trouble is when I am deserializing the object in C#, I get an error saying "Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List
1[JLL.BTP.DealioService.Models.Dealio.DealAllocation]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.`"
How to overcome this problem. I want to have an Response Class and want to deserialize the JSON response to the Response Class.
Any suggestions would be greatly appreciated !!