Mennan
Mennan

Reputation: 4497

How to Parse Json Array on C#

i am trying to parse Json Array using JSON.net on C#.How can i do it easily?

    [
   {
      "1":[
         "Fax1",
         "Fax2",
         "Fax3"
      ]
   },
   {
      "2":[
         "Voice1",
         "Voice2",
         "Voice3"
      ]
   },
   {
      "3":[
         "IVR1",
         "IVR2",
         "IVR3"
      ]
   }
]

Upvotes: 1

Views: 6192

Answers (1)

Alex
Alex

Reputation: 6149

You can do it using Newtonsoft.Json.Linq Library, here is a sample:

DataContext.Configuration.ProxyCreationEnabled = false;
JArray usersArray = JArray.FromObject(from users in DataContext.Users.AsEnumerable()
                                                 select new
                                                 {
                                                     users.ID,
                                                     users.Name
                                                 });
            JObject obj = new JObject(new JProperty("users", usersArray));
            Response.Write(obj);

Upvotes: 1

Related Questions