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


C# JsonReader.ReadToken方法代码示例

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


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

示例1: ImportFromArray

        protected override object ImportFromArray(ImportContext context, JsonReader reader)
        {
            if (_single)
                return _importer(context, reader);

            reader.Read();
            var result = _importer(context, reader);
            reader.ReadToken(JsonTokenClass.EndArray);
            return result;
        }
开发者ID:db48x,项目名称:KeeFox,代码行数:10,代码来源:TupleImporter.cs

示例2: ImportArray

        private object ImportArray(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);

            reader.ReadToken(JsonTokenClass.Array);
            var list = new List<object>();
            while (reader.TokenClass != JsonTokenClass.EndArray)
                list.Add(ImportValue(context, reader));
            reader.Read();
            return new ReadOnlyCollection<object>(list);
        }
开发者ID:RyanWangTHU,项目名称:ccv2,代码行数:12,代码来源:ExpandoObjectImporter.cs

示例3: ImportFromObject

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

            reader.ReadToken(JsonTokenClass.Object);
            var expando = (IDictionary<string, object>) new ExpandoObject();
            while (reader.TokenClass != JsonTokenClass.EndObject)
                expando[reader.ReadMember()] = ImportValue(context, reader);
            reader.Read();
            return expando;
        }
开发者ID:RyanWangTHU,项目名称:ccv2,代码行数:12,代码来源:ExpandoObjectImporter.cs

示例4: SubImport

        protected override object SubImport(JsonReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            reader.ReadToken(JsonTokenClass.Object);
            
            object o = Activator.CreateInstance(_type);
            
            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();
               
                PropertyDescriptor property = _properties[memberName];
                
                if (property != null)
                    property.SetValue(o, reader.Get(property.PropertyType));
            }
         
            return o;
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:21,代码来源:ComponentImporter.cs

示例5: DecodeChildNodes

        private static void DecodeChildNodes(JsonReader reader, XmlWriter writer) 
        {
            Debug.Assert(reader != null);
            Debug.Assert(writer != null);

            reader.ReadToken(JsonTokenClass.Array);
            
            while (reader.TokenClass != JsonTokenClass.EndArray)
            {
                if (reader.TokenClass == JsonTokenClass.Object)
                {
                    DecodeObjectForm(reader, writer);
                }
                else if (reader.TokenClass == JsonTokenClass.Array)
                {
                    throw new JsonMLException("JSON array is not a valid child node.");
                }
                else
                {
                    if (reader.TokenClass != JsonTokenClass.Null)
                        writer.WriteString(reader.Text);
                    reader.Read();
                }
            }
            
            reader.Read();
        }
开发者ID:db48x,项目名称:KeeFox,代码行数:27,代码来源:JsonMLCodec.cs

示例6: DecodeObjectForm

        /// <summary>
        /// Converts JsonML in object form to XML.
        /// </summary>

        public static void DecodeObjectForm(JsonReader reader, XmlWriter writer)
        {
            if (reader == null) throw new ArgumentNullException("reader");
            if (writer == null) throw new ArgumentNullException("writer");

            reader.ReadToken(JsonTokenClass.Object);

            string tagName = null;
            JsonObject attributes = null;
            JsonRecorder childNodes = null;
            ArrayList childNodesList = null;
            
            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();
                
                switch (memberName)
                {
                    case "tagName":
                    {
                        if (tagName != null && string.CompareOrdinal(reader.Text, tagName) != 0)
                            throw new JsonMLException("Tag name already defined.");
                        tagName = reader.Text;
                        if (tagName.Length == 0)
                            throw new JsonMLException("Tag name cannot be empty.");
                        reader.Read();
                        break;
                    }
                    case "childNodes":
                    {
                        if (reader.TokenClass == JsonTokenClass.Null)
                        {
                            reader.Read();
                        }
                        else
                        {
                            if (reader.TokenClass != JsonTokenClass.Array)
                                throw new JsonMLException("Child nodes must be a JSON array.");
                            
                            JsonRecorder aChildNodes = new JsonRecorder();
                            aChildNodes.WriteFromReader(reader);
                            if (childNodes == null)
                            {
                                childNodes = aChildNodes;
                            }
                            else
                            {
                                if (childNodesList == null)
                                    childNodesList = new ArrayList(4);
                                childNodesList.Add(aChildNodes);
                            }
                        }
                        break;
                    }
                    default:
                    {
                        if (attributes == null)
                            attributes = new JsonObject();
                        if (reader.TokenClass == JsonTokenClass.Array || reader.TokenClass == JsonTokenClass.Object)
                            throw new JsonMLException("Non-scalar attribute value.");
                        if (reader.TokenClass != JsonTokenClass.Null)
                            attributes.Add(memberName, reader.Text);
                        reader.Read();
                        break;
                    }
                }
            }

            reader.Read();

            if (tagName == null && writer.WriteState != WriteState.Element && writer.WriteState != WriteState.Content)
                throw new JsonMLException("Tag name not found.");

            writer.WriteStartElement(tagName);

            if (attributes != null)
            {
                foreach (JsonMember attribute in attributes)
                    writer.WriteAttributeString(attribute.Name, attribute.Value.ToString());
            }

            DecodeChildNodes(childNodes, writer);

            if (childNodesList != null)
            {
                foreach (JsonRecorder aChildNodes in childNodesList)
                    DecodeChildNodes(aChildNodes, writer);
            }

            writer.WriteEndElement();
        }
开发者ID:db48x,项目名称:KeeFox,代码行数:95,代码来源:JsonMLCodec.cs

示例7: DecodeArrayForm

        /// <summary>
        /// Converts JsonML in array form to XML.
        /// </summary>
        
        public static void DecodeArrayForm(JsonReader reader, XmlWriter writer)
        {
            if (reader == null) throw new ArgumentNullException("reader");
            if (writer == null) throw new ArgumentNullException("writer");

            reader.ReadToken(JsonTokenClass.Array);

            if (reader.TokenClass == JsonTokenClass.EndArray)
            {
                if (writer.WriteState != WriteState.Element && writer.WriteState != WriteState.Content)
                    throw new JsonMLException("Missing root element.");
            }
            else
            {
                writer.WriteStartElement(reader.ReadString());

                //
                // If there is a second element that is a JSON object then
                // it represents the element attributes.
                //

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

                    while (reader.TokenClass != JsonTokenClass.EndObject)
                    {
                        string name = reader.ReadMember();

                        if (reader.TokenClass == JsonTokenClass.Object ||
                            reader.TokenClass == JsonTokenClass.Array)
                        {
                            throw new JsonMLException(
                                "Attribute value cannot be structural, such as a JSON object or array.");
                        }

                        writer.WriteAttributeString(name,
                            reader.TokenClass == JsonTokenClass.Null ?
                                string.Empty : reader.Text);

                        reader.Read();
                    }

                    reader.Read();
                }

                //
                // Process any remaining elements as child elements
                // and text content.
                //

                while (reader.TokenClass != JsonTokenClass.EndArray)
                {
                    if (reader.TokenClass == JsonTokenClass.Object)
                    {
                        throw new JsonMLException(
                            "Found JSON object when expecting " +
                            "either a JSON array representing a child element " +
                            "or a JSON string representing text content.");
                    }

                    if (reader.TokenClass == JsonTokenClass.Array)
                    {
                        Decode(reader, writer);
                    }
                    else if (reader.TokenClass == JsonTokenClass.Null)
                    {
                        reader.Read();
                    }
                    else
                    {
                        writer.WriteString(reader.Text);
                        reader.Read();
                    }
                }

                writer.WriteEndElement();
            }

            reader.Read();
        }
开发者ID:db48x,项目名称:KeeFox,代码行数:85,代码来源:JsonMLCodec.cs

示例8: TestValue

        private static void TestValue(object expected, JsonReader reader, string path)
        {
            JsonToken actualToken = reader.ReadToken();
            
            if (JNull.LogicallyEquals(expected))
            {
                Assert.AreEqual(JsonToken.Null, actualToken, path, actualToken);
            }
            else
            {
                TypeCode expectedType = Type.GetTypeCode(expected.GetType());

                if (expectedType == TypeCode.Object)
                {
                    if (expected.GetType().IsArray)
                        TestArray((Array) expected, reader, path);
                    else
                        TestObject((JObject) expected, reader, path);
                }
                else
                {
                    string actual = reader.Text;

                    switch (expectedType)
                    {
                        case TypeCode.String : Assert.AreEqual(actualToken, JsonToken.String, path); Assert.AreEqual(expected, actual, path); break;
                        case TypeCode.Int32  : Assert.AreEqual(actualToken, JsonToken.Number, path); Assert.AreEqual(expected, int.Parse(actual), path); break;
                        default : Assert.Fail("Don't know how to handle {0} values.", expected.GetType()); break;
                    }
                }
            }
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:32,代码来源:TestComponentFormatter.cs

示例9: 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

示例10: 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

示例11: 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

示例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


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