如何在C#上解析Json数组

时间:2011-08-17 09:37:36

标签: c# json

我试图在C#上使用JSON.net解析Json数组。我怎么能轻松地完成它?

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

1 个答案:

答案 0 :(得分:1)

您可以使用Newtonsoft.Json.Linq Library来完成,这是一个示例:

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);