public static IAdaptingType Read(JsonTokenClass type, JsonReader reader, ParseContext parseContext) { if (!readers.ContainsKey(type)) { if (Log.isLogging(LoggingConstants.ERROR)) { Log.log(LoggingConstants.ERROR, string.Format("Don't know how to import {0} from JSON.", type)); } return(null); } IJsonReader jsonReader = readers[type]; return(jsonReader.read(reader, parseContext)); }
/// <summary> /// Reads the next token ensuring that it matches the specified /// token. If not, an exception is thrown. /// </summary> public string ReadToken(JsonTokenClass token) { int depth = Depth; if (!token.IsTerminator) { MoveToContent(); } // // We allow an exception to the simple case of validating // the token and returning its value. If the reader is still at // the start (depth is zero) and we're being asked to check // for the null token or a scalar-type token then we allow that // to be appear within a one-length array. This is done because // valid JSON text must begin with an array or object. Our // JsonWriterBase automatically wraps a scalar value in an // array if not done explicitly. This exception here allow // that case to pass as being logically valid, as if the // token appeared entirely on its own between BOF and EOF. // string text; if (depth == 0 && TokenClass == JsonTokenClass.Array && (token.IsScalar || token == JsonTokenClass.Null)) { Read(/* array */); text = ReadToken(token); ReadToken(JsonTokenClass.EndArray); } else { if (TokenClass != token) { throw new Exception(string.Format("Found {0} where {1} was expected.", TokenClass, token)); } text = Text; Read(); } return(text); }
private JsonToken(JsonTokenClass clazz, string text) { _class = clazz; _text = text; }
private JsonToken(JsonTokenClass clazz) : this(clazz, null) { }