-3

How to convert json to the class in C # json in the database is similarly stored and is not interchangeable

[rules][0][id]:1,
[rules][0][field]:1,
[valid]:true,
[IsActive]:true

public class FilterRule
{
    public bool IsActive { get; set; }
    public string Field { get; set; }
    public string Id { get; set; }
    public List<FilterRule> Rules { get; set; }
    public string Value { get; set; }
}
Hossein Hagh
  • 127
  • 2
  • 3
  • 15
  • Need more information. What does your JSON look like? –  Sep 13 '18 at 11:58
  • my json: [rules][0][id]:1, [rules][0][field]:1, [valid]:true, [IsActive]:true – Hossein Hagh Sep 13 '18 at 11:59
  • 4
    google "c# deserialise json" and you'll get plenty of results. The key term here is "de-serialisation". To convert the object back to JSON again would be "serialisation". It appears that since you tagged the JSON.NET library you perhaps already know about it...so what have you researched or tried so far? What exact problem are you facing? They have plenty of demos on their site. By the way, what you have shown for your data is not JSON syntax. It would be far better if you showed us actual JSON, it will be easier to understand. – ADyson Sep 13 '18 at 11:59
  • 2
    What do you mean by _json in the database is similarly stored and is not interchangeable_? – ChristianMurschall Sep 13 '18 at 12:22
  • Without a sample of your JSON there's no specific help we can give. Take a look at [Deserializing JSON data to C# using JSON.NET](https://stackoverflow.com/q/2546138), [Deserialize JSON with C#](https://stackoverflow.com/q/7895105) and/or [How to auto-generate a C# class file from a JSON object string](https://stackoverflow.com/q/21611674). – dbc Sep 15 '18 at 21:11

1 Answers1

0

You can use the following :

var model = JsonConvert.DeserializeObject<List<FilterRule>>(yourJson);

Assuming that FilterRule is the list of objects you want.

Hope it helps!

Smaiil
  • 139
  • 1
  • 5