本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.JsonTextReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextReader.Read方法的具体用法?C# JsonTextReader.Read怎么用?C# JsonTextReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Imports.Newtonsoft.Json.JsonTextReader
的用法示例。
在下文中一共展示了JsonTextReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadSingleQuoteInsideDoubleQuoteString
public void ReadSingleQuoteInsideDoubleQuoteString()
{
string json = @"{""NameOfStore"":""Forest's Bakery And Cafe""}";
JsonTextReader jsonTextReader = new JsonTextReader(new StringReader(json));
jsonTextReader.Read();
jsonTextReader.Read();
jsonTextReader.Read();
Assert.AreEqual(@"Forest's Bakery And Cafe", jsonTextReader.Value);
}
示例2: FloatParseHandling
public void FloatParseHandling()
{
string json = "[1.0,1,9.9,1E-06]";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
reader.FloatParseHandling = Json.FloatParseHandling.Decimal;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(1.0m, reader.Value);
Assert.AreEqual(typeof(decimal), reader.ValueType);
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(1L, reader.Value);
Assert.AreEqual(typeof(long), reader.ValueType);
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(9.9m, reader.Value);
Assert.AreEqual(typeof(decimal), reader.ValueType);
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(Convert.ToDecimal(1E-06), reader.Value);
Assert.AreEqual(typeof(decimal), reader.ValueType);
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
}
示例3: SurrogatePairValid
public void SurrogatePairValid()
{
string json = @"{ ""MATHEMATICAL ITALIC CAPITAL ALPHA"": ""\uD835\uDEE2"" }";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
Assert.IsTrue(reader.Read());
Assert.IsTrue(reader.Read());
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
string s = reader.Value.ToString();
Assert.AreEqual(2, s.Length);
StringInfo stringInfo = new StringInfo(s);
Assert.AreEqual(1, stringInfo.LengthInTextElements);
}
示例4: Import
public DumperStats Import(string file)
{
var stopwatch = Stopwatch.StartNew();
using (var streamReader =
new StreamReader(new GZipStream(File.OpenRead(file), CompressionMode.Decompress)))
{
var jsonReader = new JsonTextReader(streamReader);
if (jsonReader.Read() == false)
return new DumperStats();
if (jsonReader.TokenType != JsonToken.StartObject)
throw new InvalidDataException("StartObject was expected");
var indexes = new Dictionary<string, IndexDefinition>();
var indexCount = 0;
Read(jsonReader,
"Indexes",
index =>
{
indexCount++;
var indexName = index.Value<string>("name");
if (!indexName.StartsWith("Raven/"))
{
indexes[indexName] = index.Value<RavenJObject>("definition").JsonDeserialization<IndexDefinition>();
}
});
foreach (var index in indexes)
{
_documentDatabase.PutIndex(index.Key, index.Value);
}
var total = 0;
var batch = new List<RavenJObject>();
Read(jsonReader,
"Docs",
document =>
{
total++;
batch.Add((RavenJObject)document);
if (batch.Count >= 128)
{
FlushBatch(batch);
}
});
FlushBatch(batch);
stopwatch.Stop();
return new DumperStats
{
Attachments = 0,
Documents = total,
Indexes = indexCount,
Elapsed = stopwatch.Elapsed
};
}
}
示例5: ParseAndValidate
private static void ParseAndValidate(string text, int expectedLength)
{
var reader = new StringReader(text);
var jsonTextReader = new JsonTextReader(reader);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.StartObject, jsonTextReader.TokenType);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.PropertyName, jsonTextReader.TokenType);
Assert.Equal("Data", jsonTextReader.Value);
var memoryStream = jsonTextReader.ReadBytesAsStream();
Assert.Equal(expectedLength, memoryStream.Length);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.PropertyName, jsonTextReader.TokenType);
Assert.Equal("Metadata", jsonTextReader.Value);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.Null, jsonTextReader.TokenType);
Assert.True(jsonTextReader.Read());
Assert.Equal(JsonToken.EndObject, jsonTextReader.TokenType);
Assert.False(jsonTextReader.Read());
}
示例6: ReadMultilineString
public void ReadMultilineString()
{
string json = @"""first line
second line
third line""";
JsonTextReader jsonTextReader = new JsonTextReader(new StringReader(json));
Assert.IsTrue(jsonTextReader.Read());
Assert.AreEqual(JsonToken.String, jsonTextReader.TokenType);
Assert.AreEqual(@"first line
second line
third line", jsonTextReader.Value);
}
示例7: ThrowErrorWhenParsingUnquoteStringThatStartsWithNE
public void ThrowErrorWhenParsingUnquoteStringThatStartsWithNE()
{
const string json = @"{ ""ItemName"": ""value"", ""u"":netanelsalinger,""r"":9 }";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
ExceptionAssert.Throws<JsonReaderException>("Unexpected content while parsing JSON. Path 'u', line 1, position 27.",
() =>
{
reader.Read();
});
}
示例8: ReadSingleValueAsStreamShouldWork
public void ReadSingleValueAsStreamShouldWork(int size)
{
var random = new Random(size);
var buffer = new byte[size];
random.NextBytes(buffer);
var d = new Data
{
Foo = buffer
};
var jsonObj = RavenJToken.FromObject(d);
var jsonObjAsString = jsonObj.ToString();
using (var textReader = new StringReader(jsonObjAsString))
using (var jsonReader = new JsonTextReader(textReader))
{
jsonReader.Read(); // start object
jsonReader.Read(); // property name
var actual = new byte[buffer.Length];
using (var objectStream = jsonReader.ReadBytesAsStream())
{
objectStream.Read(actual, 0, actual.Length);
for (int a = 0; a < actual.Length; a++)
{
if (buffer[a] != actual[a])
{
Assert.True(false, "not equal on byte " + a);
}
}
}
}
}
示例9: ReadBytesNoStartWithUnexpectedEnd
public void ReadBytesNoStartWithUnexpectedEnd()
{
JsonReader reader = new JsonTextReader(new StringReader(@"[ "));
Assert.IsTrue(reader.Read());
Assert.IsNull(reader.ReadAsBytes());
Assert.AreEqual(JsonToken.None, reader.TokenType);
}
示例10: UnexpectedEndOfControlCharacter
public void UnexpectedEndOfControlCharacter()
{
JsonReader reader = new JsonTextReader(new StringReader(@"'h\"));
ExceptionAssert.Throws<JsonReaderException>(
"Unterminated string. Expected delimiter: '. Path '', line 1, position 3.",
() =>
{
reader.Read();
});
}
示例11: UnexpectedEndOfHex
public void UnexpectedEndOfHex()
{
JsonReader reader = new JsonTextReader(new StringReader(@"'h\u123"));
ExceptionAssert.Throws<JsonReaderException>(
"Unexpected end while parsing unicode character. Path '', line 1, position 4.",
() =>
{
reader.Read();
});
}
示例12: ReadNullTerminatorStrings
public void ReadNullTerminatorStrings()
{
JsonReader reader = new JsonTextReader(new StringReader("'h\0i'"));
Assert.IsTrue(reader.Read());
Assert.AreEqual("h\0i", reader.Value);
}
示例13: AppendCharsWhileReadingNewLine
public void AppendCharsWhileReadingNewLine()
{
string json = @"
{
""description"": ""A person"",
""type"": ""object"",
""properties"":
{
""name"": {""type"":""string""},
""hobbies"": {
""type"": ""array"",
""items"": {""type"":""string""}
}
}
}
";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[129]);
#endif
for (int i = 0; i < 14; i++)
{
Assert.IsTrue(reader.Read());
}
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
Assert.AreEqual("type", reader.Value);
}
示例14: ReadInt64Overflow_Negative
public void ReadInt64Overflow_Negative()
{
BigInteger i = new BigInteger(long.MinValue);
JsonTextReader reader = new JsonTextReader(new StringReader(i.ToString(CultureInfo.InvariantCulture)));
reader.Read();
Assert.AreEqual(typeof(long), reader.ValueType);
for (int j = 1; j < 1000; j++)
{
BigInteger total = i + -j;
reader = new JsonTextReader(new StringReader(total.ToString(CultureInfo.InvariantCulture)));
reader.Read();
Assert.AreEqual(typeof(BigInteger), reader.ValueType);
}
}
示例15: ReadingIndented
public void ReadingIndented()
{
string input = @"{
CPU: 'Intel',
Drives: [
'DVD read/writer',
""500 gigabyte hard drive""
]
}";
StringReader sr = new StringReader(input);
using (JsonTextReader jsonReader = new JsonTextReader(sr))
{
#if DEBUG
jsonReader.SetCharBuffer(new char[5]);
#endif
Assert.AreEqual(jsonReader.TokenType, JsonToken.None);
Assert.AreEqual(0, jsonReader.LineNumber);
Assert.AreEqual(0, jsonReader.LinePosition);
jsonReader.Read();
Assert.AreEqual(jsonReader.TokenType, JsonToken.StartObject);
Assert.AreEqual(1, jsonReader.LineNumber);
Assert.AreEqual(1, jsonReader.LinePosition);
jsonReader.Read();
Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName);
Assert.AreEqual(jsonReader.Value, "CPU");
Assert.AreEqual(2, jsonReader.LineNumber);
Assert.AreEqual(7, jsonReader.LinePosition);
jsonReader.Read();
Assert.AreEqual(JsonToken.String, jsonReader.TokenType);
Assert.AreEqual("Intel", jsonReader.Value);
Assert.AreEqual(2, jsonReader.LineNumber);
Assert.AreEqual(15, jsonReader.LinePosition);
jsonReader.Read();
Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName);
Assert.AreEqual(jsonReader.Value, "Drives");
Assert.AreEqual(3, jsonReader.LineNumber);
Assert.AreEqual(10, jsonReader.LinePosition);
jsonReader.Read();
Assert.AreEqual(jsonReader.TokenType, JsonToken.StartArray);
Assert.AreEqual(3, jsonReader.LineNumber);
Assert.AreEqual(12, jsonReader.LinePosition);
jsonReader.Read();
Assert.AreEqual(jsonReader.TokenType, JsonToken.String);
Assert.AreEqual(jsonReader.Value, "DVD read/writer");
Assert.AreEqual(jsonReader.QuoteChar, '\'');
Assert.AreEqual(4, jsonReader.LineNumber);
Assert.AreEqual(22, jsonReader.LinePosition);
jsonReader.Read();
Assert.AreEqual(jsonReader.TokenType, JsonToken.String);
Assert.AreEqual(jsonReader.Value, "500 gigabyte hard drive");
Assert.AreEqual(jsonReader.QuoteChar, '"');
Assert.AreEqual(5, jsonReader.LineNumber);
Assert.AreEqual(30, jsonReader.LinePosition);
jsonReader.Read();
Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray);
Assert.AreEqual(6, jsonReader.LineNumber);
Assert.AreEqual(4, jsonReader.LinePosition);
jsonReader.Read();
Assert.AreEqual(jsonReader.TokenType, JsonToken.EndObject);
Assert.AreEqual(7, jsonReader.LineNumber);
Assert.AreEqual(2, jsonReader.LinePosition);
Assert.IsFalse(jsonReader.Read());
}
}