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


C# JsonReader.ReadAndMoveToContent方法代码示例

本文整理汇总了C#中JsonReader.ReadAndMoveToContent方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.ReadAndMoveToContent方法的具体用法?C# JsonReader.ReadAndMoveToContent怎么用?C# JsonReader.ReadAndMoveToContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonReader的用法示例。


在下文中一共展示了JsonReader.ReadAndMoveToContent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateJObject

        private JToken CreateJObject(JsonReader reader)
        {
            ValidationUtils.ArgumentNotNull(reader, nameof(reader));

            // this is needed because we've already read inside the object, looking for metadata properties
            using (JTokenWriter writer = new JTokenWriter())
            {
                writer.WriteStartObject();

                do
                {
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        string propertyName = (string)reader.Value;
                        if (!reader.ReadAndMoveToContent())
                        {
                            break;
                        }

                        if (CheckPropertyName(reader, propertyName))
                        {
                            continue;
                        }

                        writer.WritePropertyName(propertyName);
                        writer.WriteToken(reader, true, true, false);
                    }
                    else if (reader.TokenType == JsonToken.Comment)
                    {
                        // eat
                    }
                    else
                    {
                        writer.WriteEndObject();
                        return writer.Token;
                    }
                } while (reader.Read());

                throw JsonSerializationException.Create(reader, "Unexpected end when deserializing object.");
            }
        }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:41,代码来源:JsonSerializerInternalReader.cs

示例2: ReadForType

        private bool ReadForType(JsonReader reader, JsonContract contract, bool hasConverter)
        {
            // don't read properties with converters as a specific value
            // the value might be a string which will then get converted which will error if read as date for example
            if (hasConverter)
            {
                return reader.Read();
            }

            ReadType t = (contract != null) ? contract.InternalReadType : ReadType.Read;

            switch (t)
            {
                case ReadType.Read:
                    return reader.ReadAndMoveToContent();
                case ReadType.ReadAsInt32:
                    reader.ReadAsInt32();
                    break;
                case ReadType.ReadAsDecimal:
                    reader.ReadAsDecimal();
                    break;
                case ReadType.ReadAsDouble:
                    reader.ReadAsDouble();
                    break;
                case ReadType.ReadAsBytes:
                    reader.ReadAsBytes();
                    break;
                case ReadType.ReadAsBoolean:
                    reader.ReadAsBoolean();
                    break;
                case ReadType.ReadAsString:
                    reader.ReadAsString();
                    break;
                case ReadType.ReadAsDateTime:
                    reader.ReadAsDateTime();
                    break;
#if !NET20
                case ReadType.ReadAsDateTimeOffset:
                    reader.ReadAsDateTimeOffset();
                    break;
#endif
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return (reader.TokenType != JsonToken.None);
        }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:47,代码来源:JsonSerializerInternalReader.cs


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