My server sends me JSON with a list of errors. If there is more than one error, it looks like this:
{
"ErrorFuncional": [
{
"ErrorCode": "1020",
"ErrorReason": "xxxx",
"ErrorPosition": "xxxx",
"OriginalValue": "33333"
},
{
"ErrorCode": "103",
"ErrorReason": "xxxx",
"ErrorPosition": "xxxx",
"OriginalValue": "111"
},
{
"ErrorCode": "110901",
"ErrorReason": "xxxx",
"ErrorPosition": "xxxx",
"OriginalValue": "222"
}
]
}
But if there is only one error, the JSON looks like this:
{
"ErrorFuncional":
{
"ErrorCode": "1020",
"ErrorReason": "xxxx",
"ErrorPosition": "xxxx",
"OriginalValue": "33333"
}
}
I defined the errors variable as an array, so when trying to parse one error, an exception occurs.
Is there a way to convert a single error into an array with one element before parsing it to JSON? If not, how should I handle this scenario?
Thank you!