protected static JsonValue ParseObject(char[] json, ref int index) { JsonValue result = new JsonValue(); result.Object = new Dictionary<string, JsonValue>(); int token; // { NextToken(json, ref index); bool done = false; while (!done) { token = LookAhead(json, index); if (token == JSON.TOKEN_NONE) { result.Empty(); return result; } else if (token == JSON.TOKEN_COMMA) { NextToken(json, ref index); } else if (token == JSON.TOKEN_CURLY_CLOSE) { NextToken(json, ref index); break; } else { // name JsonValue name = ParseString(json, ref index); if (name.Type != JsonType.String) { result.Empty(); return result; } // : token = NextToken(json, ref index); if (token != JSON.TOKEN_COLON) { result.Empty(); return result; } // value JsonValue value = ParseValue(json, ref index); if (value.Type == JsonType.None) { return value; } result.Object[name.String] = value; } } return result; }
protected static JsonValue ParseArray(char[] json, ref int index) { JsonValue result = new JsonValue(); result.Array = new List<JsonValue>(); // [ NextToken(json, ref index); bool done = false; while (!done) { int token = LookAhead(json, index); if (token == JSON.TOKEN_NONE) { result.Empty(); return result; } else if (token == JSON.TOKEN_COMMA) { NextToken(json, ref index); } else if (token == JSON.TOKEN_SQUARED_CLOSE) { NextToken(json, ref index); break; } else { JsonValue value = ParseValue(json, ref index); if (value.Type == JsonType.None) { return value; } result.Array.Add(value); } } return result; }