C# 使用JPath查询节点(正则表达式)

public class RouteManager
    {
        private JObject jsonObject = new JObject();

        public void AddRoute(string webPath, string resourcePath)
        {
            jsonObject.AddChild(webPath, resourcePath);
        }

        public string GetResourcePathByRoute(string webPath)
        {
            var result = jsonObject.SelectToken($"$..[?(@=~/{webPath.Trim('/')}/ig)]");
            if (result != null)
            {
                return result.Value<string>();
            }
            return null;
        }
    }

本身写了个相似路由的功能,用到了Json,正则匹配比较方便web

相关文章
相关标签/搜索