Hi,
I am very new to web development and I am developing a web app using ASP.NET MVC 5.I have a requirement to deserialize a json string and store the values in C# Objects
This is how my JSON looks like
{
"spellCheckQuery": "abc*",
"searchStatus": "OK",
"results": [
{
"id": "Enterprise 1 ",
"attributes": [
{
"value": "Vertical",
"id": "name",
"label": "Name"
},
{
"value": "Logical grouping of products based on the physical properties and delivery mechanism of the product. Verticals include: O ",
"id": "infa_description",
"label": "Description"
}
],
"fragments": [
{
"fragments": [
"abc"
],
"attrId": "name"
},
{
"fragments": [
"abc"
],
"attrId": "infa_description"
}
],
"categoryIds": [
"Enterprise "
]
},
{
"id": "Enterprise 2",
"attributes": [
{
"value": "Logical grouping of products based on patient condition. The 11 Franchises include",
"id": "infa_description",
"label": "Description"
},
{
"value": "Franchise",
"id": "name",
"label": "Name"
}
],
"fragments": [
{
"fragments": [
"abc"
],
"attrId": "name"
},
{
"fragments": [
"abc"
],
"attrId": "infa_description"
}
],
"categoryIds": [
"Enterprise"
]
}
],
"originalQuery": "abc*",
"resultCount": 2,
"categoryDetail": [
{
"id": "Enterprise",
"path": [
"Enterprise Business Glossary",
"abc"
],
"description": [
"abc Enterprise Business Glossary",
"some text goes here"
]
}
],
"processingTime": 45
}
Below are the classes that I have created
public class Attribute
{
public string value { get; set; }
public string id { get; set; }
public string label { get; set; }
}
public class Fragment
{
public List fragments { get; set; }
public string attrId { get; set; }
}
public class Result
{
public string id { get; set; }
public List attributes { get; set; }
public List fragments { get; set; }
public List categoryIds { get; set; }
}
public class CategoryDetail
{
public string id { get; set; }
public List path { get; set; }
public List description { get; set; }
}
public class RootObject
{
public string spellCheckQuery { get; set; }
public string searchStatus { get; set; }
public List results { get; set; }
public string originalQuery { get; set; }
public int resultCount { get; set; }
public List categoryDetail { get; set; }
public int processingTime { get; set; }
}
I have used below code to deserialize:
RootObject dobj = JsonConvert.DeserializeObject
My question is that the json has 2 result count with Ids enterprise 1 and Enterprise 2 respectively.I want to display these two result sets as my output. How can I achieve this? Any help would be greatly appreciated.
What I have tried:
RootObject dobj = JsonConvert.DeserializeObject