本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.JsonReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.Read方法的具体用法?C# JsonReader.Read怎么用?C# JsonReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Imports.Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var collection = new NameValueCollection();
while (reader.Read())
{
if (reader.TokenType == JsonToken.EndObject)
break;
var key = (string)reader.Value;
if (reader.Read() == false)
throw new InvalidOperationException("Expected PropertyName, got " + reader.TokenType);
if (reader.TokenType == JsonToken.StartArray)
{
var values = serializer.Deserialize<string[]>(reader);
foreach (var value in values)
{
collection.Add(key, value);
}
}
else
{
collection.Add(key, reader.Value.ToString());
}
}
return collection;
}
示例2: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
reader.Read();
Debug.Assert(reader.TokenType == JsonToken.PropertyName);
Debug.Assert((string)reader.Value == "coordinates");
if (objectType == typeof(Coordinate))
{
return ReadJsonCoordinate(reader);
}
if (typeof(IEnumerable<Coordinate>).IsAssignableFrom(objectType))
{
return ReadJsonCoordinates(reader);
}
if (typeof(List<Coordinate[]>).IsAssignableFrom(objectType))
{
return ReadJsonCoordinatesEnumerable(reader);
}
if (typeof(List<List<Coordinate[]>>).IsAssignableFrom(objectType))
{
return ReadJsonCoordinatesEnumerable2(reader);
}
throw new Exception();
}
示例3: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
reader.Read();
if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "geometries"))
{
throw new Exception();
}
reader.Read();
if (reader.TokenType != JsonToken.StartArray)
throw new Exception();
reader.Read();
List<IGeometry> geoms = new List<IGeometry>();
while (reader.TokenType != JsonToken.EndArray)
{
JObject obj = (JObject)serializer.Deserialize(reader);
GeoJsonObjectType geometryType = (GeoJsonObjectType)Enum.Parse(typeof(GeoJsonObjectType), obj.Value<string>("type"));
switch (geometryType)
{
case GeoJsonObjectType.Point:
geoms.Add(this._factory.CreatePoint(ToCoordinate(obj.Value<JArray>("coordinates"))));
break;
case GeoJsonObjectType.LineString:
geoms.Add(this._factory.CreateLineString(ToCoordinates(obj.Value<JArray>("coordinates"))));
break;
case GeoJsonObjectType.Polygon:
geoms.Add(this.CreatePolygon(ToListOfCoordinates(obj.Value<JArray>("coordinates"))));
break;
case GeoJsonObjectType.MultiPoint:
geoms.Add(this._factory.CreateMultiPoint(ToCoordinates(obj.Value<JArray>("coordinates"))));
break;
case GeoJsonObjectType.MultiLineString:
geoms.Add(this.CreateMultiLineString(ToListOfCoordinates(obj.Value<JArray>("coordinates"))));
break;
case GeoJsonObjectType.MultiPolygon:
geoms.Add(this.CreateMultiPolygon(ToListOfListOfCoordinates(obj.Value<JArray>("coordinates"))));
break;
case GeoJsonObjectType.GeometryCollection:
throw new NotSupportedException();
}
reader.Read();
}
return geoms;
}
示例4: ReadModel
private Model ReadModel(JsonReader reader) {
while (reader.TokenType == JsonToken.Comment) {
if (!reader.Read()) throw new JsonSerializationException("Unexpected Token when converting Model object");
}
if (reader.TokenType != JsonToken.StartObject) {
throw new JsonSerializationException("Unexpected Token when converting Model object");
}
var obj = new Model { };
while (reader.Read()) {
switch (reader.TokenType) {
case JsonToken.PropertyName:
var propertyName = reader.Value.ToString();
if (!reader.Read()) {
throw new JsonSerializationException("Unexpected end when reading Model object");
}
if (propertyName == "Id") {
obj.Id = (string)this.ReadValue(reader);
break;
}
if (propertyName == "_shurikenMeta") {
obj._shurikenMeta = this.ReadMetaData(reader);
break;
}
var v = this.ReadValue(reader);
obj[propertyName] = v;
break;
case JsonToken.Comment:
break;
case JsonToken.EndObject:
return obj;
}
}
throw new JsonSerializationException("Unexpected end when reading Model object");
}
示例5: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
{
var list = (IList) Activator.CreateInstance(objectType);
while (reader.Read())
{
if (reader.TokenType == JsonToken.EndArray)
break;
reader.Read(); //CrlType prop name
reader.Read(); //actual type
Type type = Type.GetType((string) reader.Value);
reader.Read(); // value property
reader.Read(); // actual value
object item = serializer.Deserialize(reader, type);
list.Add(item);
reader.Read(); // end object
}
return list;
}
示例6: ImportIndexes
private async Task<int> ImportIndexes(JsonReader jsonReader, SmugglerOptions options)
{
var count = 0;
if (jsonReader.Read() == false)
return count;
if (jsonReader.TokenType != JsonToken.PropertyName)
throw new InvalidDataException("PropertyName was expected");
if (Equals("Indexes", jsonReader.Value) == false)
throw new InvalidDataException("Indexes property was expected");
if (jsonReader.Read() == false)
return count;
if (jsonReader.TokenType != JsonToken.StartArray)
throw new InvalidDataException("StartArray was expected");
while (jsonReader.Read() && jsonReader.TokenType != JsonToken.EndArray)
{
var index = (RavenJObject)RavenJToken.ReadFrom(jsonReader);
if ((options.OperateOnTypes & ItemType.Indexes) != ItemType.Indexes)
continue;
var indexName = index.Value<string>("name");
if (indexName.StartsWith("Temp/"))
continue;
if (index.Value<RavenJObject>("definition").Value<bool>("IsCompiled"))
continue; // can't import compiled indexes
if ((options.OperateOnTypes & ItemType.RemoveAnalyzers) == ItemType.RemoveAnalyzers)
{
index.Value<RavenJObject>("definition").Remove("Analyzers");
}
await PutIndex(indexName, index);
count++;
}
await PutIndex(null, null);
return count;
}
示例7: WriteToken
internal void WriteToken(JsonReader reader, int initialDepth, bool writeChildren)
{
do
{
switch (reader.TokenType)
{
case JsonToken.None:
// read to next
break;
case JsonToken.StartObject:
WriteStartObject();
break;
case JsonToken.StartArray:
WriteStartArray();
break;
case JsonToken.StartConstructor:
string constructorName = reader.Value.ToString();
// write a JValue date when the constructor is for a date
if (string.Equals(constructorName, "Date", StringComparison.Ordinal))
WriteConstructorDate(reader);
else
WriteStartConstructor(reader.Value.ToString());
break;
case JsonToken.PropertyName:
WritePropertyName(reader.Value.ToString());
break;
case JsonToken.Comment:
WriteComment((reader.Value != null) ? reader.Value.ToString() : null);
break;
case JsonToken.Integer:
WriteValue(Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture));
break;
case JsonToken.Float:
object value = reader.Value;
if (value is decimal)
WriteValue((decimal)value);
else if (value is double)
WriteValue((double)value);
else if (value is float)
WriteValue((float)value);
else
WriteValue(Convert.ToDouble(value, CultureInfo.InvariantCulture));
break;
case JsonToken.String:
WriteValue(reader.Value.ToString());
break;
case JsonToken.Boolean:
WriteValue(Convert.ToBoolean(reader.Value, CultureInfo.InvariantCulture));
break;
case JsonToken.Null:
WriteNull();
break;
case JsonToken.Undefined:
WriteUndefined();
break;
case JsonToken.EndObject:
WriteEndObject();
break;
case JsonToken.EndArray:
WriteEndArray();
break;
case JsonToken.EndConstructor:
WriteEndConstructor();
break;
case JsonToken.Date:
#if !PocketPC && !NET20
if (reader.Value is DateTimeOffset)
WriteValue((DateTimeOffset)reader.Value);
else
#endif
WriteValue(Convert.ToDateTime(reader.Value, CultureInfo.InvariantCulture));
break;
case JsonToken.Raw:
WriteRawValue((reader.Value != null) ? reader.Value.ToString() : null);
break;
case JsonToken.Bytes:
WriteValue((byte[])reader.Value);
break;
default:
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("TokenType", reader.TokenType, "Unexpected token type.");
}
}
while (
// stop if we have reached the end of the token being read
initialDepth - 1 < reader.Depth - (IsEndToken(reader.TokenType) ? 1 : 0)
&& writeChildren
&& reader.Read());
}
示例8: Read
private static void Read(JsonReader jsonReader, string arrayName, Action<RavenJToken> process)
{
if (jsonReader.Read() == false)
return;
if (jsonReader.TokenType != JsonToken.PropertyName)
throw new InvalidDataException("PropertyName was expected");
if (Equals(arrayName, jsonReader.Value) == false)
throw new InvalidDataException(arrayName + " property was expected");
if (jsonReader.Read() == false)
return;
if (jsonReader.TokenType != JsonToken.StartArray)
throw new InvalidDataException("StartArray was expected");
while (jsonReader.Read() && jsonReader.TokenType != JsonToken.EndArray)
{
var token = RavenJToken.ReadFrom(jsonReader);
process(token);
}
}
示例9: ReadMetaData
private Model.MetaData ReadMetaData(JsonReader reader) {
if (reader.TokenType == JsonToken.Null) {
return null;
}
var obj = new Model.MetaData { };
var t = obj.GetType();
while (reader.Read()) {
switch (reader.TokenType) {
case JsonToken.PropertyName:
var propertyName = reader.Value.ToString();
if (!reader.Read()) {
throw new JsonSerializationException("Unexpected end when reading Model object");
}
var p = t.GetProperty(propertyName);
if (p.PropertyType == typeof(DateTime)) {
var d = DateTime.Parse(reader.Value as string).ToUniversalTime();
p.SetValue(obj, d);
break;
}
p.SetValue(obj, reader.Value);
break;
case JsonToken.Comment:
break;
case JsonToken.EndObject:
return obj;
}
}
throw new JsonSerializationException("Unexpected end when reading Model object");
}
示例10: ReadJsonCoordinates
private static Coordinate[] ReadJsonCoordinates(JsonReader reader)
{
reader.Read();
if (reader.TokenType != JsonToken.StartArray) return null;
List<Coordinate> coordinates = new List<Coordinate>();
while (true)
{
Coordinate c = ReadJsonCoordinate(reader);
if (c == null) break;
coordinates.Add(c);
}
Debug.Assert(reader.TokenType == JsonToken.EndArray);
return coordinates.ToArray();
}
示例11: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
reader.Read();
if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "type"))
{
throw new Exception();
}
reader.Read();
if (reader.TokenType != JsonToken.String)
{
throw new Exception();
}
GeoJsonObjectType geometryType = (GeoJsonObjectType)Enum.Parse(typeof (GeoJsonObjectType), (string) reader.Value);
switch (geometryType)
{
case GeoJsonObjectType.Point:
Coordinate coordinate = serializer.Deserialize<Coordinate>(reader);
return this._factory.CreatePoint(coordinate);
case GeoJsonObjectType.LineString:
Coordinate[] coordinates = serializer.Deserialize<Coordinate[]>(reader);
return this._factory.CreateLineString(coordinates);
case GeoJsonObjectType.Polygon:
List<Coordinate[]> coordinatess = serializer.Deserialize<List<Coordinate[]>>(reader);
return this.CreatePolygon(coordinatess);
case GeoJsonObjectType.MultiPoint:
coordinates = serializer.Deserialize<Coordinate[]>(reader);
return this._factory.CreateMultiPoint(coordinates);
case GeoJsonObjectType.MultiLineString:
coordinatess = serializer.Deserialize<List<Coordinate[]>>(reader);
List<ILineString> strings = new List<ILineString>();
for (int i = 0; i < coordinatess.Count; i++)
strings.Add(this._factory.CreateLineString(coordinatess[i]));
return this._factory.CreateMultiLineString(strings.ToArray());
case GeoJsonObjectType.MultiPolygon:
List<List<Coordinate[]>> coordinatesss = serializer.Deserialize<List<List<Coordinate[]>>>(reader);
List<IPolygon> polygons = new List<IPolygon>();
foreach (List<Coordinate[]> coordinateses in coordinatesss)
polygons.Add(this.CreatePolygon(coordinateses));
return this._factory.CreateMultiPolygon(polygons.ToArray());
case GeoJsonObjectType.GeometryCollection:
List<IGeometry> geoms = serializer.Deserialize<List<IGeometry>>(reader);
return this._factory.CreateGeometryCollection(geoms.ToArray());
//ReadJson(reader,)
}
return null;
}
示例12: ReadObject
private object ReadObject(JsonReader reader) {
var obj = new Dough();
while (reader.Read()) {
switch (reader.TokenType) {
case JsonToken.PropertyName:
var propertyName = reader.Value.ToString();
if (!reader.Read()) {
throw new JsonSerializationException("Unexpected end when reading Model object");
}
var v = this.ReadValue(reader);
obj[propertyName] = v;
break;
case JsonToken.Comment:
break;
case JsonToken.EndObject:
return obj;
}
}
throw new JsonSerializationException("Unexpected end when reading Model object");
}
示例13: ReadArray
private object ReadArray(JsonReader reader) {
IList<object> list = new List<object>();
while (reader.Read()) {
switch (reader.TokenType) {
case JsonToken.Comment:
break;
default:
var v = this.ReadValue(reader);
list.Add(v);
break;
case JsonToken.EndArray:
return list;
}
}
throw new JsonSerializationException("Unexpected end when reading Model object");
}
示例14: ReadValue
private object ReadValue(JsonReader reader) {
while (reader.TokenType == JsonToken.Comment) {
if (!reader.Read()) throw new JsonSerializationException("Unexpected Token when converting Model object");
}
switch (reader.TokenType) {
case JsonToken.StartObject:
return this.ReadObject(reader);
case JsonToken.StartArray:
return this.ReadArray(reader);
case JsonToken.Integer:
case JsonToken.Float:
case JsonToken.String:
case JsonToken.Boolean:
case JsonToken.Undefined:
case JsonToken.Null:
case JsonToken.Date:
case JsonToken.Bytes:
return reader.Value;
default:
throw new JsonSerializationException
(string.Format("Unexpected token when converting Model object: {0}", reader.TokenType));
}
}
示例15: WriteToken
internal void WriteToken(JsonReader reader, int initialDepth, bool writeChildren, bool writeDateConstructorAsDate)
{
do
{
// write a JValue date when the constructor is for a date
if (writeDateConstructorAsDate && reader.TokenType == JsonToken.StartConstructor && string.Equals(reader.Value.ToString(), "Date", StringComparison.Ordinal))
WriteConstructorDate(reader);
else
WriteTokenInternal(reader.TokenType, reader.Value);
} while (
// stop if we have reached the end of the token being read
initialDepth - 1 < reader.Depth - (JsonTokenUtils.IsEndToken(reader.TokenType) ? 1 : 0)
&& writeChildren
&& reader.Read());
}