예제 #1
0
 public Utf8String GetUtf8String() { return JsonString.Unquote(Segment); }
예제 #2
0
 public String GetString() { return JsonString.Unquote(Segment.ToString()); }
예제 #3
0
        public IEnumerable <JsonNode> GetNodes(JsonPointer jsonPointer)
        {
            if (jsonPointer.Path.Count == 0)
            {
                yield return(this);

                yield break;
            }

            if (Value.ValueType == JsonValueType.Array)
            {
                // array
                if (jsonPointer[0] == "*")
                {
                    // wildcard
                    foreach (var child in ArrayItems)
                    {
                        foreach (var childChild in child.GetNodes(jsonPointer.Unshift()))
                        {
                            yield return(childChild);
                        }
                    }
                }
                else
                {
                    int index;
                    if (!int.TryParse(jsonPointer[0], out index))
                    {
                        throw new KeyNotFoundException();
                    }
                    var child = this[index];
                    foreach (var childChild in child.GetNodes(jsonPointer.Unshift()))
                    {
                        yield return(childChild);
                    }
                }
            }
            else if (Value.ValueType == JsonValueType.Object)
            {
                // object
                if (jsonPointer[0] == "*")
                {
                    // wildcard
                    foreach (var kv in ObjectItems)
                    {
                        foreach (var childChild in kv.Value.GetNodes(jsonPointer.Unshift()))
                        {
                            yield return(childChild);
                        }
                    }
                }
                else
                {
                    JsonNode child;
                    try
                    {
                        child = this[jsonPointer[0]];
                    }
                    catch (KeyNotFoundException)
                    {
                        // key
                        Values.Add(new JsonValue(new StringSegment(JsonString.Quote(jsonPointer[0])), JsonValueType.String, m_index));
                        // value
                        Values.Add(new JsonValue(new StringSegment(), JsonValueType.Object, m_index));

                        child = this[jsonPointer[0]];
                    }
                    foreach (var childChild in child.GetNodes(jsonPointer.Unshift()))
                    {
                        yield return(childChild);
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
예제 #4
0
 public JsonValue Key(Utf8String key, int parentIndex)
 {
     return new JsonValue(JsonString.Quote(key), ValueNodeType.String, parentIndex);
 }
예제 #5
0
        public String GetString()
        {
            var quoted = Segment.ToString();

            return(JsonString.Unquote(quoted));
        }