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

相關文章
相關標籤/搜索