Deserialize inconsistent single/array data from UPS RESTful API

127 Views Asked by At

Running into an issue with the UPS RESTful API. We have tried to create well typed classes to deserialize their responses into, but it seems like sometimes they return a single node and other times an array for certain data. for the attached image their docs say RatedShipment should be an array/list of objects and yet sometimes they return a single node. same thing for the RatedShipmentAlert below. is there any way to have the class it deserializes to be "flexible" and handle either instance? right now we have the object as RatedShipment As List(Of Rate_RateResponse_RatedShipment) and that fails on the deserialize when it's a single object.

objRateResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Response_RateResponse)(objResponse.Content)

Thanks in advance,

result

0

There are 0 best solutions below