1234567891011121314151617181920212223242526 |
- using Newtonsoft.Json;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public static class GameTool
- {
- //用于获取多层级Dictionary中的value
- public static string GetValueAtPath(Dictionary<string, object> root, string[] path)
- {
- Dictionary<string, object> current = root;
- int count = 0;
- foreach (string key in path)
- {
- string rawValue = current[key].ToString();
- rawValue = Regex.Replace(rawValue, @"[\r\n]", "");
- if (count == path.Length - 1)
- {
- return rawValue;
- }
- Dictionary<string, object> value = JsonConvert.DeserializeObject<Dictionary<string, object>>(rawValue);
- current = value;
- count++;
- }
- return null;
- }
- }
|