void ParseContent(JsonNode obj, string jsonString, ref int index) { Token token = PeekToken(jsonString, index); switch (token) { case Token.String: { string value = ParseString(jsonString, ref index); obj.AddValue(value); } break; case Token.Number: { object number = ParseNumber(jsonString, ref index); obj.AddValue(number); } break; case Token.ObjectOpen: { ParseObject(obj, jsonString, ref index); } break; case Token.ArrayOpen: { ParseArray(obj, jsonString, ref index); } break; case Token.True: { NextToken(jsonString, ref index); obj.AddValue(true); } break; case Token.False: { NextToken(jsonString, ref index); obj.AddValue(false); } break; case Token.Null: { NextToken(jsonString, ref index); obj.AddValue(null); } break; case Token.None: break; default: throw new InvalidDataException(string.Format("Json object, value or array expected at position {0}, got {1}!", index, token)); } }
/// <summary> /// Gets the value with the specified index (array only). /// </summary> /// <param name="index"></param> /// <returns></returns> public JsonNode this[int index] { get { if (Type == JsonNodeType.Array) { object value = ((ArrayList)content)[index]; if (value is JsonNode node) { return(node); } node = new JsonNode(JsonNodeType.Value, string.Empty); node.AddValue(value); return(node); } return(null); } }