0

I am trying to extract the below key-value pair in JSON to dictonary.

var str = @" 
{
   ""tables"": {
    ""category"": ""Category"",
    ""subcategory"": ""SubCategory"",
    ""tfs"": ""tfs"",
    ""tickets"": ""snowtickets"",
    ""ticketcategoryauto"": ""TicketCategoryAuto"",
    ""ticketcategoryuserselected"": ""TicketCategoryManual""
  }
}
";


  var jo = JObject.Parse(str);
  var x = from c in jo["tables"] select c;

I want the "tables" node of this Json into a dictionary object. so if I say x["category"] should get back "Category" similarly for other keys. How can I do that.

Shiju Samuel
  • 1,373
  • 6
  • 22
  • 45

1 Answers1

3

tables is a dictionary type object so you need to return it as a type of Dictionary.

var jo = JObject.Parse(str);
Dictionary<string, string> values = jo["tables"].ToObject<Dictionary<string,string>>();
Brian Rogers
  • 125,747
  • 31
  • 299
  • 300
Navoneel Talukdar
  • 4,393
  • 5
  • 21
  • 42