当前位置: 首页>>代码示例>>C#>>正文


C# JsonConverter.ReadJson方法代码示例

本文整理汇总了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);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:7,代码来源:JsonSerializerInternalReader.cs

示例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);
      }
    }
开发者ID:Contatta,项目名称:Newtonsoft.Json,代码行数:36,代码来源:JsonSerializerInternalReader.cs

示例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;
        }
开发者ID:rv192,项目名称:Fussen,代码行数:12,代码来源:JsonSerializerInternalReader.cs

示例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.");
        }
开发者ID:AndyStewart,项目名称:docsharp,代码行数:63,代码来源:JsonSerializerInternalReader.cs

示例5: DeserializeConvertable

 private object DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, object existingValue)
 {
     object value = converter.ReadJson(reader, objectType, existingValue, GetInternalSerializer());
     return value;
 }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:5,代码来源:JsonSerializerInternalReader.cs

示例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.");
        }
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:53,代码来源:JsonSerializerReader.cs

示例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;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:15,代码来源:JsonSerializerInternalReader.cs

示例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.");
        }
开发者ID:utunga,项目名称:Tradeify,代码行数:72,代码来源:JsonSerializerInternalReader.cs


注:本文中的JsonConverter.ReadJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。