GameTool.cs 807 B

1234567891011121314151617181920212223242526
  1. using Newtonsoft.Json;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. public static class GameTool
  5. {
  6. //ÓÃÓÚ»ñÈ¡¶à²ã¼¶DictionaryÖеÄvalue
  7. public static string GetValueAtPath(Dictionary<string, object> root, string[] path)
  8. {
  9. Dictionary<string, object> current = root;
  10. int count = 0;
  11. foreach (string key in path)
  12. {
  13. string rawValue = current[key].ToString();
  14. rawValue = Regex.Replace(rawValue, @"[\r\n]", "");
  15. if (count == path.Length - 1)
  16. {
  17. return rawValue;
  18. }
  19. Dictionary<string, object> value = JsonConvert.DeserializeObject<Dictionary<string, object>>(rawValue);
  20. current = value;
  21. count++;
  22. }
  23. return null;
  24. }
  25. }