JSON string to model / HashMap/ Dictionary in C#

Viewed 7151

I have JSON:

{
"One": [
{
  "ID": 1,
  "name": "s"
},
{
  "categoryID": 2,
  "name": "c"
}
],
"Two": [
{
  "ID": 3,
  "name": "l"
}
],
"Three": [
{
  "ID": 8,
  "name": "s&P"
},
{
  "ID": 52,
  "name": "BB"
}
]
}

I want to:

  1. Take this JSON to any object(like JObject)

  2. Filter the JSON on different conditions(like name start with s, etc

  3. Return this JSON to client

Things I have tried: 1. Creating models:

class Model
{
public int Id;
public string name;
}
class MainModel
{
public string mainName;
public List<Model> categories;
}

And use these model to:

List<MainModel> m = json_serializer.DeserializeObject(jsonString);
  1. I tried to Dictionary also but getting unable to cast exception.

any help would be appreciated.

2 Answers
Related