Retrieve the values from json string

后端 未结 5 753
忘掉有多难
忘掉有多难 2021-01-26 05:33

I have json string. I want to retrieve the contact from json string. Following json contains array of contacts. here is my json string

5条回答
  •  春和景丽
    2021-01-26 06:05

    1. First make sure your Json is in valid format using jsonlint

    2. Then generate class base on it using json2csharp

      public class Field
      {
          public int id { get; set; }
          public string type { get; set; }
          public object value { get; set; }
          public string editedBy { get; set; }
          public List flags { get; set; }
          public List categories { get; set; }
          public string updated { get; set; }
          public string created { get; set; }
      }
      
      public class Contact
      {
          public bool isConnection { get; set; }
          public int id { get; set; }
          public List fields { get; set; }
      }
      
      public class Contacts
      {
          public List contact { get; set; }
      }
      
      public class RootObject
      {
          public Contacts contacts { get; set; }
      }
      
      
    3. Use Newtonsoft JSON to deserialize your Json into object(s) then you may simply access its properties value.

      JsonConvert.DeserializeObject(string json);
      
    4. 提交回复
      热议问题