本文整理汇总了C#中JsonConverter.ReadJson方法的典型用法代码示例。如果您正苦于以下问题:C# JsonConverter.ReadJson方法的具体用法?C# JsonConverter.ReadJson怎么用?C# JsonConverter.ReadJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonConverter
的用法示例。
在下文中一共展示了JsonConverter.ReadJson方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateValueNonProperty
private object CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract, JsonConverter converter)
{
if (converter != null && converter.CanRead)
return converter.ReadJson(reader, objectType, null, GetInternalSerializer());
return CreateValueInternal(reader, objectType, contract, null, null);
}
示例2: SetPropertyValue
private void SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, object target)
{
object currentValue;
bool useExistingValue;
JsonContract propertyContract;
bool gottenCurrentValue;
if (CalculatePropertyDetails(property, ref propertyConverter, containerContract, containerProperty, reader, target, out useExistingValue, out currentValue, out propertyContract, out gottenCurrentValue))
return;
object value;
if (propertyConverter != null && propertyConverter.CanRead)
{
if (!gottenCurrentValue && target != null && property.Readable)
currentValue = property.ValueProvider.GetValue(target);
value = propertyConverter.ReadJson(reader, property.PropertyType, currentValue, GetInternalSerializer());
}
else
{
value = CreateValueInternal(reader, property.PropertyType, propertyContract, property, containerContract, containerProperty, (useExistingValue) ? currentValue : null);
}
// always set the value if useExistingValue is false,
// otherwise also set it if CreateValue returns a new value compared to the currentValue
// this could happen because of a JsonConverter against the type
if ((!useExistingValue || value != currentValue)
&& ShouldSetPropertyValue(property, value))
{
property.ValueProvider.SetValue(target, value);
if (property.SetIsSpecified != null)
property.SetIsSpecified(target, true);
}
}
示例3: DeserializeConvertable
private object DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, object existingValue)
{
if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Info)
TraceWriter.Trace(TraceLevel.Info, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "Started deserializing {0} with converter {1}.".FormatWith(CultureInfo.InvariantCulture, objectType, converter.GetType())), null);
object value = converter.ReadJson(reader, objectType, existingValue, GetInternalSerializer());
if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Info)
TraceWriter.Trace(TraceLevel.Info, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "Finished deserializing {0} with converter {1}.".FormatWith(CultureInfo.InvariantCulture, objectType, converter.GetType())), null);
return value;
}
示例4: CreateValue
private object CreateValue(JsonReader reader, Type objectType, JsonContract contract, object existingValue, JsonConverter memberConverter)
{
JsonConverter converter;
if (memberConverter != null)
return memberConverter.ReadJson(reader, objectType, GetInternalSerializer());
if (contract != null && contract.Converter != null)
return contract.Converter.ReadJson(reader, objectType, GetInternalSerializer());
if (objectType != null && Serializer.HasMatchingConverter(objectType, out converter))
return converter.ReadJson(reader, objectType, GetInternalSerializer());
if (contract is JsonLinqContract)
return CreateJToken(reader, contract);
do
{
switch (reader.TokenType)
{
// populate a typed object or generic dictionary/array
// depending upon whether an objectType was supplied
case JsonToken.StartObject:
return CreateObject(reader, objectType, contract, existingValue);
case JsonToken.StartArray:
return CreateList(reader, objectType, contract, existingValue, null);
case JsonToken.Integer:
case JsonToken.Float:
case JsonToken.Boolean:
case JsonToken.Date:
case JsonToken.Bytes:
return EnsureType(reader.Value, objectType);
case JsonToken.String:
// convert empty string to null automatically for nullable types
if (string.IsNullOrEmpty((string)reader.Value) &&
objectType != null &&
ReflectionUtils.IsNullableType(objectType))
return null;
return EnsureType(reader.Value, objectType);
case JsonToken.StartConstructor:
case JsonToken.EndConstructor:
string constructorName = reader.Value.ToString();
return constructorName;
case JsonToken.Null:
case JsonToken.Undefined:
if (objectType == typeof (DBNull))
return DBNull.Value;
return EnsureType(reader.Value, objectType);
case JsonToken.Raw:
return new JRaw((string)reader.Value);
case JsonToken.Comment:
// ignore
break;
default:
throw new JsonSerializationException("Unexpected token while deserializing object: " + reader.TokenType);
}
} while (reader.Read());
throw new JsonSerializationException("Unexpected end when deserializing object.");
}
示例5: DeserializeConvertable
private object DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, object existingValue)
{
object value = converter.ReadJson(reader, objectType, existingValue, GetInternalSerializer());
return value;
}
示例6: CreateValue
private object CreateValue(JsonReader reader, Type objectType, object existingValue, JsonConverter memberConverter)
{
JsonConverter converter;
if (memberConverter != null)
return memberConverter.ReadJson(reader, objectType, GetInternalSerializer());
if (objectType != null && _serializer.HasClassConverter(objectType, out converter))
return converter.ReadJson(reader, objectType, GetInternalSerializer());
if (objectType != null && _serializer.HasMatchingConverter(objectType, out converter))
return converter.ReadJson(reader, objectType, GetInternalSerializer());
if (objectType == typeof (JsonRaw))
return JsonRaw.Create(reader);
do
{
switch (reader.TokenType)
{
// populate a typed object or generic dictionary/array
// depending upon whether an objectType was supplied
case JsonToken.StartObject:
return CreateObject(reader, objectType, existingValue);
case JsonToken.StartArray:
return CreateList(reader, objectType, existingValue, null);
case JsonToken.Integer:
case JsonToken.Float:
case JsonToken.String:
case JsonToken.Boolean:
case JsonToken.Date:
return EnsureType(reader.Value, objectType);
case JsonToken.StartConstructor:
case JsonToken.EndConstructor:
string constructorName = reader.Value.ToString();
return constructorName;
case JsonToken.Null:
case JsonToken.Undefined:
if (objectType == typeof (DBNull))
return DBNull.Value;
return null;
case JsonToken.Comment:
// ignore
break;
default:
throw new JsonSerializationException("Unexpected token while deserializing object: " + reader.TokenType);
}
} while (reader.Read());
throw new JsonSerializationException("Unexpected end when deserializing object.");
}
示例7: DeserializeConvertable
// Token: 0x06000BD8 RID: 3032
// RVA: 0x00045C64 File Offset: 0x00043E64
private object DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, object existingValue)
{
if (this.TraceWriter != null && this.TraceWriter.LevelFilter >= TraceLevel.Info)
{
this.TraceWriter.Trace(TraceLevel.Info, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, StringUtils.FormatWith("Started deserializing {0} with converter {1}.", CultureInfo.InvariantCulture, objectType, converter.GetType())), null);
}
object result = converter.ReadJson(reader, objectType, existingValue, this.GetInternalSerializer());
if (this.TraceWriter != null && this.TraceWriter.LevelFilter >= TraceLevel.Info)
{
this.TraceWriter.Trace(TraceLevel.Info, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, StringUtils.FormatWith("Finished deserializing {0} with converter {1}.", CultureInfo.InvariantCulture, objectType, converter.GetType())), null);
}
return result;
}
示例8: CreateValue
private object CreateValue(JsonReader reader, Type objectType, object existingValue, JsonConverter memberConverter)
{
JsonConverter converter;
if (memberConverter != null)
return memberConverter.ReadJson(reader, objectType, GetInternalSerializer());
if (objectType != null && Serializer.HasClassConverter(objectType, out converter))
return converter.ReadJson(reader, objectType, GetInternalSerializer());
if (objectType != null && Serializer.HasMatchingConverter(objectType, out converter))
return converter.ReadJson(reader, objectType, GetInternalSerializer());
if (objectType == typeof (JsonRaw))
return JsonRaw.Create(reader);
do
{
switch (reader.TokenType)
{
// populate a typed object or generic dictionary/array
// depending upon whether an objectType was supplied
case JsonToken.StartObject:
return CreateObject(reader, objectType, existingValue);
case JsonToken.StartArray:
return CreateList(reader, objectType, existingValue, null);
case JsonToken.Integer:
case JsonToken.Float:
case JsonToken.String:
case JsonToken.Boolean:
case JsonToken.Date:
// convert empty string to null automatically
/////////////////////////
//MKT:2009-11-21 why in the name of god would you wan tto do that?
//orig:
//if (reader.Value is string &&
// string.IsNullOrEmpty((string)reader.Value) &&
// objectType != null &&
// ReflectionUtils.IsNullable(objectType))
// return null;
if (reader.Value is string && reader.Value==null &&
objectType != null &&
ReflectionUtils.IsNullable(objectType))
return null;
/////////////////////////
return EnsureType(reader.Value, objectType);
case JsonToken.StartConstructor:
case JsonToken.EndConstructor:
string constructorName = reader.Value.ToString();
return constructorName;
case JsonToken.Null:
case JsonToken.Undefined:
if (objectType == typeof (DBNull))
return DBNull.Value;
return null;
case JsonToken.Comment:
// ignore
break;
default:
throw new JsonSerializationException("Unexpected token while deserializing object: " + reader.TokenType);
}
} while (reader.Read());
throw new JsonSerializationException("Unexpected end when deserializing object.");
}