Read() публичный Метод

Reads the next JSON token from the stream.
public Read ( ) : bool
Результат bool
        /// <summary>
        /// Verifies Json literal content 
        /// </summary>
        /// <param name="content">the Json literal to be verified</param>
        /// <param name="result">output paramter of test result</param>
        /// <returns>true if verification passes; false otherwiser</returns>
        public bool Verify(string content, out TestResult result)
        {
            using (var stringReader = new StringReader(content))
            {
                using (JsonTextReader rdr = new JsonTextReader(stringReader))
                {
                    using (JsonValidatingReader vr = new JsonValidatingReader(rdr))
                    {
                        vr.Schema = this.schema;

                        try
                        {
                            while (vr.Read())
                            {
                                // Ignore
                            }

                            result = new TestResult();
                            return true;
                        }
                        catch (JsonSchemaException jex)
                        {
                            result = new TestResult() { LineNumberInError = jex.LineNumber, ErrorDetail = jex.Message };
                            return false;
                        }
                    }
                }
            }
        }
Пример #2
0
 public static void Validate(this JToken source, JsonSchema schema, ValidationEventHandler validationEventHandler)
 {
   ValidationUtils.ArgumentNotNull((object) source, "source");
   ValidationUtils.ArgumentNotNull((object) schema, "schema");
   using (JsonValidatingReader validatingReader = new JsonValidatingReader(source.CreateReader()))
   {
     validatingReader.Schema = schema;
     if (validationEventHandler != null)
       validatingReader.ValidationEventHandler += validationEventHandler;
     do
       ;
     while (validatingReader.Read());
   }
 }