-1

I'm building an app in c# and i need to parse / create / edit / delete inforamtions (etc...) in a .json file. Underneeth is how the file .json will look like.

I was thinking of doing dynamic arrow of class (don't know if it is the way we say it in english). Is there a faster and simpler way to do this?

Thank you very much!

{
  "name": [
   {
     "var1": string or int,
     "var2": string or int,
     etc..
     .
     .
     .
   },
   {
     "var1": string or int,
     "var2": string or int,
     etc..
     .
     .
     .
   }
 ]
}
lucky simon
  • 241
  • 1
  • 6
  • 22

1 Answers1

2

First make two classes as follows:

public class Name
{
   public List<SampleObject> SampleObjects {get; set;}
}

public class SampleObject
{
    public int var1;
    public int var2;
   ....
}

Then try as follows:

public void JsonFileReader()
{
    using (StreamReader r = new StreamReader("yourJsonFile.json"))
    {
        string json = r.ReadToEnd();
        List<Name> items = JsonConvert.DeserializeObject<Name>(json);
    }
}

Note: Don't forget to adding using Newtonsoft.Json

TanvirArjel
  • 30,049
  • 14
  • 78
  • 114