Exemplo n.º 1
0
        /// <summary>
        /// Navigates through JSON datamap by subsequent node names.
        /// </summary>
        /// <returns>
        /// null if navigation path is not exists.
        /// JSONDataMap if navigation ends up with non-leaf node.
        /// object if navigation ends up with leaf node.</returns>
        public static object GetNodeByPath(this JsonDataMap json, params string[] nodeNames)
        {
            object node = null;

            for (int i = 0; i < nodeNames.Length; i++)
            {
                if (json == null || !json.TryGetValue(nodeNames[i], out node))
                {
                    return(null);
                }

                if (i == nodeNames.Length - 1)
                {
                    return(node);
                }

                json = node as JsonDataMap;
            }

            return(null);
        }