I am using RestSharp to call an API which is returning JSON. I send the API a list of IDs and the API returns info for each ID in some JSON array with key being the ID. What is the best approach to deserialize this dynamic info into C# objects?
var response = client.Get<MyObject>(request); //deserializes JSON response to MyObject
So far I have a class which is able to deserialize the timestamp, status, code, message, and errors fine, but I am not sure how to handle the ids node.
I tried using JSON to C# tools, but they create a new object for each ID in the response.
Ex) Request:
www.apiExample.com/v3/info?ids=1,2,3&market=US
Response:
{
"timestamp": 1605486853,
"status": "SUCCESS",
"statusCode": 200,
"statusMessage": "Ok",
"result": {
"errors": [],
"ids": {
"1": {
"US": [
{
"name": "name1",
"offer": {
"price": {
"currencyCode": "USD",
"amount": 8.95
}
}
}
]
},
"2": {
"US": [
{
"name": "name2",
"offer": {
"price": {
"currencyCode": "USD",
"amount": 7.95
}
}
}
]
},
"3": {
"US": [
{
"name": "name3",
"offer": {
"price": {
"currencyCode": "USD",
"amount": 9.95
}
}
}
]
}
}
}
}