本文整理汇总了C#中Newtonsoft.Json.JsonReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.Read方法的具体用法?C# JsonReader.Read怎么用?C# JsonReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalReadJson
private static object InternalReadJson(JsonReader reader, JsonSerializer serializer)
{
if (reader.TokenType != JsonToken.StartObject)
throw new ArgumentException("Expected token '{' not found.");
reader.Read();
AttributesTable attributesTable = new AttributesTable();
while (reader.TokenType == JsonToken.PropertyName)
{
string attributeName = (string) reader.Value;
reader.Read();
object attributeValue;
if (reader.TokenType == JsonToken.StartObject)
{
// inner object
attributeValue = InternalReadJson(reader, serializer);
}
else
{
attributeValue = reader.Value;
}
reader.Read();
attributesTable.AddAttribute(attributeName, attributeValue);
}
return attributesTable;
}
示例2: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.String)
{
var ret = LogLevel.FromString((string)reader.Value);
return ret;
}
else if (reader.TokenType == JsonToken.StartObject)
{
reader.Read();
if (reader.TokenType == JsonToken.PropertyName && String.Equals((string)reader.Value, "name", StringComparison.OrdinalIgnoreCase))
{
reader.Read();
if (reader.TokenType == JsonToken.String)
{
string val = (string)reader.Value;
reader.Read();
Debug.Assert(reader.TokenType == JsonToken.EndObject);
return LogLevel.FromString(val);
}
}
}
return null;
}
示例3: ProcessToken
private object ProcessToken(JsonReader reader)
{
// Recursively processes a token. This is required for elements that next other elements.
object processedObject = null;
if (reader.TokenType == JsonToken.StartObject)
{
Dictionary<string, object> dictionaryValue = new Dictionary<string, object>();
while (reader.Read() && reader.TokenType != JsonToken.EndObject)
{
string elementKey = reader.Value.ToString();
reader.Read();
dictionaryValue.Add(elementKey, ProcessToken(reader));
}
processedObject = dictionaryValue;
}
else if (reader.TokenType == JsonToken.StartArray)
{
List<object> arrayValue = new List<object>();
while (reader.Read() && reader.TokenType != JsonToken.EndArray)
{
arrayValue.Add(ProcessToken(reader));
}
processedObject = arrayValue.ToArray();
}
else
{
processedObject = reader.Value;
}
return processedObject;
}
示例4: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
FunctionInputOutput functionInputOutput = new FunctionInputOutput();
int startingDepth = reader.Depth;
while (!(reader.TokenType == JsonToken.EndObject && reader.Depth == startingDepth))
{
reader.Read();
if (reader.TokenType == JsonToken.PropertyName)
{
string propertyName = reader.Value.ToString();
if (String.Equals(propertyName, "name"))
{
reader.Read();
functionInputOutput.Name = reader.Value.ToString();
}
else if (String.Equals(propertyName, "type"))
{
reader.Read();
functionInputOutput.Type = reader.Value.ToString();
}
}
}
return functionInputOutput;
}
示例5: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
List<Sex> result = new List<Sex> ();
// now tokentype is [
reader.Read ();
while (reader.TokenType == JsonToken.String)
{
string enumString = (string)reader.Value;
switch (enumString)
{
case "man":
result.Add (Sex.Male);
break;
case "woman":
result.Add (Sex.Female);
break;
default:
throw new Exception ("Wrong sex");
}
reader.Read ();
}
return result;
}
示例6: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
if (reader.TokenType != JsonToken.StartArray)
{
return null;
}
reader.Read();
var coords = new double[2];
for (int i = 0; i < 2; ++i)
{
if (reader.TokenType == JsonToken.Float)
{
coords[i] = (double)reader.Value;
reader.Read();
}
else if (reader.TokenType == JsonToken.Integer)
{
coords[i] = (double)((long)reader.Value);
reader.Read();
}
}
var latitude = coords[0];
var longitude = coords[1];
return new TwitterGeoLocation.GeoCoordinates { Latitude = latitude, Longitude = longitude };
}
示例7: ReadArray
private TypeReference[] ReadArray(JsonReader reader)
{
var singleItem = ReadItem(reader);
if (singleItem != null)
{
return new[] { singleItem };
}
if (reader.TokenType != JsonToken.StartArray)
{
throw new ArgumentException("Unexpected token type " + reader.TokenType);
}
var tokens = new List<TypeReference>();
reader.Read();
while (reader.TokenType != JsonToken.EndArray)
{
singleItem = ReadItem(reader);
if (singleItem != null)
{
tokens.Add(singleItem);
reader.Read();
continue;
}
throw new ArgumentException("Unexpected token type " + reader.TokenType);
}
return tokens.ToArray();
}
示例8: ReadId
private static long ReadId(JsonReader reader)
{
reader.Read();
long type = (long)reader.Value;
reader.Read();
return type;
}
示例9: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (ReflectionUtils.IsNullableType(objectType))
Nullable.GetUnderlyingType(objectType);
if (reader.TokenType == JsonToken.Null)
{
if (!ReflectionUtils.IsNullable(objectType))
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Cannot convert null value to {0}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) objectType));
else
return (object) null;
}
else
{
if (reader.TokenType != JsonToken.StartConstructor || !string.Equals(reader.Value.ToString(), "Date", StringComparison.Ordinal))
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token or value when parsing date. Token: {0}, Value: {1}", (IFormatProvider) CultureInfo.InvariantCulture, (object) reader.TokenType, reader.Value));
reader.Read();
if (reader.TokenType != JsonToken.Integer)
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token parsing date. Expected Integer, got {0}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) reader.TokenType));
DateTime dateTime = JsonConvert.ConvertJavaScriptTicksToDateTime((long) reader.Value);
reader.Read();
if (reader.TokenType != JsonToken.EndConstructor)
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token parsing date. Expected EndConstructor, got {0}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) reader.TokenType));
else
return (object) dateTime;
}
}
示例10: ReadType
private static string ReadType(JsonReader reader)
{
reader.Read();
string type = (string)reader.Value;
reader.Read();
return type;
}
示例11: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType != JsonToken.StartObject)
throw new JsonException("Expected {");
var results = new List<InputAlias>();
reader.Read();
while (reader.TokenType != JsonToken.EndObject)
{
if (reader.TokenType != JsonToken.PropertyName)
throw new JsonException("Expected property name");
var alias = (string)reader.Value;
reader.Read();
if (reader.TokenType != JsonToken.String)
throw new JsonException("Expected string");
var value = (string)reader.Value;
results.Add(new InputAlias
{
Name = alias,
Value = value
});
reader.Read();
}
return results.ToArray();
}
示例12: Read
public IConfigureCloudQueueMessageEnvelope Read(JsonReader reader)
{
if (reader == null) throw new ArgumentNullException("reader");
IConfigureCloudQueueMessageEnvelope envelope = new CloudQueueMessageEnvelope();
reader.Read(); //StartObject
reader.Read(); //PropertyName:From
envelope = envelope.SetFrom(reader.ReadAsString()); //String:From value
reader.Read(); //PropertyName:To
envelope = envelope.SetTo(reader.ReadAsString()); //String:To value
reader.Read(); //PropertyName:MessageId
envelope = envelope.SetMessageId(new Guid(reader.ReadAsString())); //String:MessageId value
reader.Read();
if (((string)reader.Value) == "RelatesToMessageId") //PropertyName:Possibly RelatesToMessageId
{
envelope = envelope.SetRelatesToMessageId(new Guid(reader.ReadAsString()));
reader.Read(); //PropertyName:CorrelationId
}
envelope = envelope.SetCorrelationId(new Guid(reader.ReadAsString())); //String:CorrelationId value
reader.Read(); //PropertyName:ContentType
envelope = envelope.SetContentType(reader.ReadAsString()); //String:ContentType value
reader.Read(); //PropertyName:Content
envelope = envelope.SetContent(reader.ReadAsBytes()); //String:Content value
reader.Read(); //PropertyName:Time
envelope = envelope.SetTime(reader.ReadAsDateTimeOffset().GetValueOrDefault()); //String:Time value
reader.Read(); //EndObject
return envelope;
}
示例13: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var itemType = objectType.GenericTypeArguments.Single();
if (reader.TokenType == JsonToken.StartObject)
{
object itemsArray = null;
LimitsReturned limitsReturned = null;
while (reader.Read())
{
if (reader.TokenType == JsonToken.StartArray)
{
//Items Array
itemsArray = serializer.Deserialize(reader, itemType.MakeArrayType());
}
else if (reader.TokenType == JsonToken.PropertyName && ((string)reader.Value).Equals("limits", StringComparison.OrdinalIgnoreCase))
{
reader.Read();
limitsReturned = serializer.Deserialize<LimitsReturned>(reader);
}
}
if (limitsReturned == null)
{
throw new InvalidOperationException("Limits nicht gefunden!");
}
return Activator.CreateInstance(objectType, itemsArray, limitsReturned);
}
throw new InvalidOperationException("Der JsonReader muss auf einem Objekt stehen!");
}
示例14: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
EthSolidityContract contract = new EthSolidityContract();
int startingDepth = reader.Depth;
while (!(reader.TokenType == JsonToken.EndObject && reader.Depth == startingDepth))
{
reader.Read();
if (reader.TokenType == JsonToken.PropertyName)
{
string propertyName = reader.Value.ToString();
if (String.Equals(propertyName, "code"))
{
reader.Read();
contract.Code = serializer.Deserialize<byte[]>(reader);
}
else if (String.Equals(propertyName, "info"))
{
reader.Read();
contract.Info = serializer.Deserialize<ContractInfo>(reader);
}
else
{
contract.ContractName = reader.Value.ToString();
reader.Read();
}
}
}
return contract;
}
示例15: ReadObject
private object ReadObject(JsonReader reader)
{
var obj = new Dictionary<string, object>();
while (reader.Read())
{
switch (reader.TokenType)
{
case JsonToken.PropertyName:
var propertyName = reader.Value.ToString();
if (!reader.Read())
{
throw new JsonSerializationException("Unexpected end when reading IDictionary<string, object>");
}
var value = ReadValue(reader);
obj[propertyName] = value;
break;
case JsonToken.Comment:
break;
case JsonToken.EndObject:
return obj;
}
}
throw new JsonSerializationException("Unexpected end when reading IDictionary<string, object>");
}