public int GetArray(JsonBuffer[] values, int index, int count) { if (index < 0) { throw new ArgumentOutOfRangeException("index", index, null); } JsonBufferReader reader = CreateReader(); if (!reader.MoveToContent()) { throw new JsonException("Unexpected EOF."); } if (reader.TokenClass == JsonTokenClass.Null) { return(0); } reader.ReadToken(JsonTokenClass.Array); int readCount = 0; while (reader.TokenClass != JsonTokenClass.EndArray) { if (count-- == 0) { return(~readCount); } if (values != null) { values[index++] = reader.BufferValue(); } else { reader.Skip(); } readCount++; } return(readCount); }
public int GetMembers(NamedJsonBuffer[] members, int index, int count) { if (index < 0) { throw new ArgumentOutOfRangeException("index", index, null); } JsonBufferReader reader = CreateReader(); if (!reader.MoveToContent()) { throw new JsonException("Unexpected EOF."); } if (reader.TokenClass == JsonTokenClass.Null) { return(0); } reader.ReadToken(JsonTokenClass.Object); int readCount = 0; while (reader.TokenClass == JsonTokenClass.Member) { if (count-- == 0) { return(~readCount); } if (members != null) { members[index++] = new NamedJsonBuffer(reader.Text, reader.BufferValue()); } else { reader.Skip(); } readCount++; } return(readCount); }
public static JsonBuffer From(JsonReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } JsonBufferReader bufferReader = reader as JsonBufferReader; if (bufferReader != null) { return(bufferReader.BufferValue()); } if (!reader.MoveToContent()) { return(Empty); } if (reader.TokenClass == JsonTokenClass.Member) { reader.Read(); } bool structured = reader.TokenClass == JsonTokenClass.Array || reader.TokenClass == JsonTokenClass.Object; JsonBufferWriter writer = new JsonBufferWriter(); writer.WriteFromReader(reader); JsonBuffer buffer = writer.GetBuffer(); if (!structured) { bufferReader = buffer.CreateReader(); bufferReader.MoveToContent(); bufferReader.Read(); buffer = bufferReader.BufferValue(); } return(buffer); }