I am using an API for car HP and PCP details. When API returns the response object it has some dynamic object and objects names depending upon the parameters given during JSON call input parameters. Please tell me how can I convert / deserialize this response object into C# object. I tried JSON convert to C# classes but didn't get required results. Given below in API response object. I need to parse this result object into C# object so i can use it for displaying required values on front end.
JSON Response / Result Object
{
"success": true,
"data": {
"hp": {
"58995": {
"48": {
"40": {
"9000": [
{
"balance": 58955,
"first": 1403.62,
"regular": 1403.62,
"final": 1413.62,
"total": 67423.76,
"charges": 8428.76,
"apr": 6.92,
"apr_nofees": 6.91,
"term": 48,
"flat": 3.57,
"fee_front": "0.00",
"fee_back": "10.00",
"fee_spread": 0,
"ref": "1000.00",
"ho": 0,
"ho_a": 0,
"sb": 0,
"id": "12",
"product_name": "HP/ML No Fees",
"excess_mileage": false
}
]
}
}
}
},
"pcp": {
"58995": {
"48": {
"40": {
"9000": [
{
"balance": 58955,
"first": 1251.04,
"regular": 1251.04,
"final": 8386,
"total": 68475.92,
"charges": 9480.92,
"apr": 6.89,
"apr_nofees": 6.89,
"rv": 8385,
"term": 48,
"flat": 3.56,
"rv_interest": 1084.68,
"charges_ex_rv": 8396.24,
"fee_front": "0.00",
"fee_back": "1.00",
"fee_spread": 0,
"ref": 0,
"ho": 0,
"ho_a": 0,
"sb": 0,
"id": "25",
"product_name": "BNP PCP",
"excess_mileage": "7p"
}
]
}
}
}
},
"count": 2,
"taken": 443
}
}
Dictionary<T,V>in C# as well. There are several duplicate questions that ask the same thing. The answers show that "objects" with arbitrary keys can be deserialized toDictionary<string,....>typeshpdynamic as well? Is the innermost object well defined? With so many levels it may be better to deserialize to a JObject and try to retrieve items element by element. ADictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,ThatObject>>>>>>>>>>>>>>>>>>>isn't fun