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


C# JsonReader.MoveToContent方法代码示例

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


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

示例1: Populate

        public void Populate(JsonReader reader, object target)
        {
            ValidationUtils.ArgumentNotNull(target, nameof(target));

            Type objectType = target.GetType();

            JsonContract contract = Serializer._contractResolver.ResolveContract(objectType);

            if (!reader.MoveToContent())
            {
                throw JsonSerializationException.Create(reader, "No JSON content found.");
            }

            if (reader.TokenType == JsonToken.StartArray)
            {
                if (contract.ContractType == JsonContractType.Array)
                {
                    JsonArrayContract arrayContract = (JsonArrayContract)contract;

                    PopulateList((arrayContract.ShouldCreateWrapper) ? arrayContract.CreateWrapper(target) : (IList)target, reader, arrayContract, null, null);
                }
                else
                {
                    throw JsonSerializationException.Create(reader, "Cannot populate JSON array onto type '{0}'.".FormatWith(CultureInfo.InvariantCulture, objectType));
                }
            }
            else if (reader.TokenType == JsonToken.StartObject)
            {
                reader.ReadAndAssert();

                string id = null;
                if (Serializer.MetadataPropertyHandling != MetadataPropertyHandling.Ignore
                    && reader.TokenType == JsonToken.PropertyName
                    && string.Equals(reader.Value.ToString(), JsonTypeReflector.IdPropertyName, StringComparison.Ordinal))
                {
                    reader.ReadAndAssert();
                    id = (reader.Value != null) ? reader.Value.ToString() : null;
                    reader.ReadAndAssert();
                }

                if (contract.ContractType == JsonContractType.Dictionary)
                {
                    JsonDictionaryContract dictionaryContract = (JsonDictionaryContract)contract;
                    PopulateDictionary((dictionaryContract.ShouldCreateWrapper) ? dictionaryContract.CreateWrapper(target) : (IDictionary)target, reader, dictionaryContract, null, id);
                }
                else if (contract.ContractType == JsonContractType.Object)
                {
                    PopulateObject(target, reader, (JsonObjectContract)contract, null, id);
                }
                else
                {
                    throw JsonSerializationException.Create(reader, "Cannot populate JSON object onto type '{0}'.".FormatWith(CultureInfo.InvariantCulture, objectType));
                }
            }
            else
            {
                throw JsonSerializationException.Create(reader, "Unexpected initial token '{0}' when populating object. Expected JSON object or array.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
            }
        }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:59,代码来源:JsonSerializerInternalReader.cs

示例2: Import

        public object Import(JsonReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            if (!reader.MoveToContent())
                throw new JsonSerializationException("Unexpected EOF.");

            if (reader.TokenClass == JsonTokenClass.Null)
                return null;
            
            return reader.DeserializeNext();
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:13,代码来源:AutoImporter.cs

示例3: Import

        public override object Import(ImportContext context, JsonReader reader)
        {
            if (reader == null) 
                throw new ArgumentNullException("reader");

            reader.MoveToContent();
            
            if (reader.TokenClass == JsonTokenClass.Null)
                return null;
            
            IJsonImportable o = CreateObject();
            o.Import(context, reader);
            return o;
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:14,代码来源:ImportAwareImporter.cs

示例4: Import

        public virtual object Import(Type type, JsonReader reader)
        {
            if (type == null)
                throw new ArgumentNullException("type");
            
            if (reader == null)
                throw new ArgumentNullException("reader");

            ITypeImporter importer = FindImporter(type);

            if (importer == null)
                throw new JsonException(string.Format("Don't know how to import {0} from JSON.", type.FullName));

            reader.MoveToContent();
            return importer.Import(this, reader);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:16,代码来源:ImportContext.cs

示例5: Import

 public virtual object Import(JsonReader reader)
 {
     if (reader == null)
         throw new ArgumentNullException("reader");
     
     if (!reader.MoveToContent())
         throw new JsonSerializationException("Unexpected EOF.");
     
     object o = null;
     
     if (reader.TokenClass != JsonTokenClass.Null)
         o = SubImport(reader);
     
     reader.Read();
     return o;
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:16,代码来源:JsonImporter.cs

示例6: Import

        public override object Import(ImportContext context, JsonReader reader)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (reader == null)
                throw new ArgumentNullException("reader");

            if (!reader.MoveToContent())
                throw new JsonException("Unexpected EOF.");
            
            if (reader.TokenClass == JsonTokenClass.Null)
            {
                reader.Read();
                return null;
            }

            Type elementType = OutputType.GetElementType();

            if (reader.TokenClass == JsonTokenClass.Array)
            {
                reader.Read();

                ArrayList list = new ArrayList();

                while (reader.TokenClass != JsonTokenClass.EndArray)
                    list.Add(context.Import(elementType, reader));

                reader.Read();
            
                return list.ToArray(elementType);
            }
            else if (reader.TokenClass == JsonTokenClass.String ||
                     reader.TokenClass == JsonTokenClass.Number ||
                     reader.TokenClass == JsonTokenClass.Boolean)
            {
                Array array = Array.CreateInstance(elementType, 1);
                array.SetValue(context.Import(elementType, reader), 0);
                return array;
            }
            else
            {
                throw new JsonException(string.Format("Found {0} where expecting JSON Array.", reader.TokenClass));
            }
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:45,代码来源:ArrayImporter.cs

示例7: Import

        public static object Import(JsonReader reader, Type type)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            if (type == null)
                type = typeof(object);

            if (!reader.MoveToContent())
                throw new JsonException("Unexpected EOF.");
                                    
            IJsonImporter importer = TryGetImporter(type);
                
            if (importer == null)
                throw new JsonException(string.Format("Don't know how to read the type {0} from JSON.", type.FullName)); // TODO: Review the choice of exception type here.

            return importer.Import(reader);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:18,代码来源:JsonImport.cs

示例8: Import

 public virtual object Import(ImportContext context, JsonReader reader)
 {
     if (context == null)
         throw new ArgumentNullException("context");
     
     if (reader == null)
         throw new ArgumentNullException("reader");
     
     if (!reader.MoveToContent())
         throw new JsonException("Unexpected EOF.");
     
     object o = null;
     
     if (reader.TokenClass != JsonTokenClass.Null)
         o = ImportValue(context, reader);
     
     reader.Read();
     return o;
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:19,代码来源:TypeImporterBase.cs

示例9: Import

        public override object Import(ImportContext context, JsonReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            reader.MoveToContent();
            
            if (reader.TokenClass == JsonTokenClass.String)
            {
                return reader.ReadString();
            }
            else if (reader.TokenClass == JsonTokenClass.Number)
            {
                return reader.ReadNumber();
            }
            else if (reader.TokenClass == JsonTokenClass.Boolean)
            {
                return reader.ReadBoolean();
            }
            else if (reader.TokenClass == JsonTokenClass.Null)
            {
                reader.Read();
                return null;
            }
            else if (reader.TokenClass == JsonTokenClass.Array)
            {
                JsonArray items = new JsonArray();
                items.Import(context, reader);
                return items;
            }
            else if (reader.TokenClass == JsonTokenClass.Object)
            {
                JsonObject o = new JsonObject();
                o.Import(context, reader);
                return o;
            }
            else 
            {
                throw new JsonException(string.Format("{0} not expected.", reader.TokenClass));
            }
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:41,代码来源:AutoImporter.cs

示例10: Import

 public virtual object Import(ImportContext context, JsonReader reader)
 {
     if (context == null)
         throw new ArgumentNullException("context");
     
     if (reader == null)
         throw new ArgumentNullException("reader");
     
     if (!reader.MoveToContent())
         throw new JsonException("Unexpected EOF.");
     
     if (reader.TokenClass == JsonTokenClass.Null)
     {
         return ImportNull(context, reader);
     }
     else if (reader.TokenClass == JsonTokenClass.String)
     {
         return ImportFromString(context, reader);
     }
     else if (reader.TokenClass == JsonTokenClass.Number)
     {
         return ImportFromNumber(context, reader);
     }
     else if (reader.TokenClass == JsonTokenClass.Boolean)
     {
         return ImportFromBoolean(context, reader);
     }
     else if (reader.TokenClass == JsonTokenClass.Array)
     {
         return ImportFromArray(context, reader);
     }
     else if (reader.TokenClass == JsonTokenClass.Object)
     {
         return ImportFromObject(context, reader);
     }
     else 
     {
         throw new JsonException(string.Format("{0} not expected.", reader.TokenClass));
     }
 }
开发者ID:db48x,项目名称:KeeFox,代码行数:40,代码来源:ImporterBase.cs

示例11: ReadValue

        private object ReadValue(JsonReader reader)
        {
            if (!reader.MoveToContent())
            {
                throw JsonSerializationException.Create(reader, "Unexpected end when reading ExpandoObject.");
            }

            switch (reader.TokenType)
            {
                case JsonToken.StartObject:
                    return ReadObject(reader);
                case JsonToken.StartArray:
                    return ReadList(reader);
                default:
                    if (JsonTokenUtils.IsPrimitiveToken(reader.TokenType))
                    {
                        return reader.Value;
                    }

                    throw JsonSerializationException.Create(reader, "Unexpected token when converting ExpandoObject: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
            }
        }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:22,代码来源:ExpandoObjectConverter.cs

示例12: TestObject

 private static void TestObject(JsonObject expected, JsonReader reader, string path)
 {
     reader.MoveToContent();
     reader.ReadToken(JsonTokenClass.Object);
     
     while (reader.TokenClass != JsonTokenClass.EndObject)
     {
         string name = reader.ReadMember();
         object value = expected[name];
         expected.Remove(name);
         TestValue(value, reader, path + "/" + name);
     }
     
     Assert.AreEqual(0, expected.Count);
     reader.Read();
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:16,代码来源:TestComponentExporter.cs

示例13: TestArray

        private static void TestArray(Array expectations, JsonReader reader, string path)
        {
            reader.MoveToContent();
            Assert.AreEqual(reader.Token, JsonToken.Array);

            for (int i = 0; i < expectations.Length; i++)
                TestValue(expectations.GetValue(i), reader, path + "/" + i);

            reader.ReadToken(JsonToken.EndArray);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:10,代码来源:TestComponentFormatter.cs

示例14: TestObject

 private static void TestObject(JObject expected, JsonReader reader, string path)
 {
     reader.MoveToContent();
     Assert.AreEqual(reader.Token, JsonToken.Object);
     
     while (reader.ReadToken() != JsonToken.EndObject)
     {
         Assert.AreEqual(JsonToken.Member, reader.Token);
         
         string name = reader.Text;
         object value = expected[name];
         expected.Remove(name);
         TestValue(value, reader, path + "/" + name);
     }
     
     Assert.AreEqual(0, expected.Count);
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:17,代码来源:TestComponentFormatter.cs

示例15: SubImport

        protected override object SubImport(JsonReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");
            
            if (!reader.MoveToContent())
                throw new JsonSerializationException("Unexpected EOF.");
            
            //
            // If got a null then that's what we return without further ado.
            //
            
            if (reader.Token == JsonToken.Null)
                return null;
            
            //
            // Reader must be sitting on an object.
            //

            if (reader.Token != JsonToken.Object)
                throw new JsonSerializationException("Expecting object.");
            
            //
            // Create the NameValueCollection object being deserialized.
            // If a hint was supplied, then that's what we will create
            // here because it could be that the caller wants to 
            // return a subtype of NameValueCollection.
            //
            
            NameValueCollection collection = CreateCollection();
            
            //
            // Loop through all members of the object.
            //

            while (reader.ReadToken() == JsonToken.Member)
            {
                string name = reader.Text;

                reader.Read();
                
                //
                // If the value is an array, then it's a multi-value 
                // entry otherwise a single-value one.
                //

                if (reader.Token == JsonToken.Array)
                {
                    while (reader.ReadToken() != JsonToken.EndArray)
                        collection.Add(name, GetValueAsString(reader));
                }
                else
                {
                    collection.Add(name, GetValueAsString(reader));    
                }
            }
            
            if (reader.Token != JsonToken.EndObject)
                throw new JsonSerializationException("Expecting end of object.");

            return collection;
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:62,代码来源:NameValueCollectionImporter.cs


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