Advertisement
Guest User

C# bojangle biscuits

a guest
Apr 1st, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1.  public static JsonSerializerOptions Options { get; } = new JsonSerializerOptions
  2.         {
  3.             PropertyNameCaseInsensitive = true,
  4.             PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
  5.             WriteIndented = true
  6.         };
  7.  
  8.  
  9.      public Dictionary<string, string> Deserialize(string text)
  10.         {
  11.             Dictionary<string, string> dictionary = new();
  12.  
  13.             try
  14.             {
  15.                 using (JsonDocument document = JsonDocument.Parse(text))
  16.                 {
  17.                     JsonElement root = document.RootElement;
  18.                     var objectEnum = root.EnumerateObject();
  19.  
  20.                     foreach (JsonProperty pair in objectEnum)
  21.                     {
  22.                         string key = pair.Name;
  23.                         JsonElement value = pair.Value;
  24.  
  25.                         dictionary.Add(key, value.ToString());
  26.                     }
  27.                 }
  28.             }
  29.             catch
  30.             {
  31.                 return null;
  32.             }
  33.  
  34.             return dictionary;
  35.  
  36.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement