Beispiel #1
0
        internal override JsonValue Query(JsonPath path)
        {
            JsonPathSection section = path.Current;

            if (section != null && section.sectionName == "$")
            {
                path.Pop(); section = path.Current;
            }

            if (section != null)
            {
                JsonString s = new JsonString(section.sectionName);
                if (_values.ContainsKey(s))
                {
                    JsonValue v = _values[s];
                    if (!(v is JsonArray))
                    {
                        path.Pop();
                    }
                    return(_values[s].Query(path));
                }
                else if (path.PathMode == JsonPathEvaluationMode.Strict)
                {
                    throw new Exception("Path error in strict mode");
                }
                else
                {
                    return(null);
                }
            }
            return(this);
        }
        internal override JsonValue Query(JsonPath path)
        {
            JsonPathSection section = path.Current;

            if (section != null)
            {
                path.Pop();
                if (section.indexerPesent)
                {
                    int indexer = section.indexerValue;
                    if (indexer >= _values.Count)
                    {
                        if (path.PathMode == JsonPathEvaluationMode.Strict)
                        {
                            throw new Exception("Path error in strict mode");
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(_values[indexer].Query(path));
                    }
                }
                else
                {
                    if (path.Current == null)
                    {
                        return(this);
                    }
                    else if (_values.Count > 0)
                    {
                        return(_values[0].Query(path));
                    }
                    else if (path.PathMode == JsonPathEvaluationMode.Strict)
                    {
                        throw new Exception("Path error in strict mode");
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            return(this);
        }