1

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"
      ]
   }
]
Mennan
  • 4,451
  • 13
  • 54
  • 86
  • Mennago. It looks like you are new over here which can be seen from your points. Did you try google it up? You can use either `JavascriptSerializer` or you can use **Json.Net** as Devendra suggested. This is the link which uses JavascriptSerializer: http://stackoverflow.com/questions/401756/parsing-json-using-json-net This is Json.Net's site: http://james.newtonking.com/pages/json-net.aspx Don't expect that we will directly post a readymade solution for you. **How can i do it easily** : Everything is easy if you take the pain and read the docs once. – TCM Aug 17 '11 at 09:58
  • Thanks Anthony, done it using Json.net ! first i tried JavascriptSerializer and it is little complicated,so i said how can i do it easily.Json.net works for me. – Mennan Aug 17 '11 at 10:12

1 Answers1

1

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);
Alex
  • 5,971
  • 11
  • 42
  • 80