How to read Dictionary inside List inside nested dictionary

  • Thread starter Thread starter gk1393
  • Start date Start date
G

gk1393

Guest
Hello,

Here is the Json sample file:-

{
"contactDetails": [],
"personDetails": [],
"serviceDetails": [
{
"serviceTypeNm": "Tax Prep",
"taxYearNo": "2019",
"productTypeNm": [],
"states": [
{



Here is what I'm trying, but it is not able to read taxYearNo.

This is the error: System.InvalidCastException : Unable to cast object of type 'RestSharp.JsonArray' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]'.

public static IRestResponse response;

var deseralize = new JsonDeserializer();
var result = deseralize.Deserialize<IList<Dictionary<string, object>>>(response);

foreach (Dictionary<string, object> temp in result)
{

if (temp.ContainsKey("serviceDetails"))
{
var obj1 = temp.GetValueOrDefault("serviceDetails");
var taxyear = ((Dictionary<string, object>)obj1).GetValueOrDefault("taxYearNo");
Assert.Equal(2019, taxYearNo());
}

}


Any help or suggestions?



Thanks,

gk03


Please do let us know your feedback. Thank You - KG, MCTS

Continue reading...
 
Back
Top