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


C# JsonReader.ReadMember方法代码示例

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


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

示例1: ImportFromObject

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

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

            //
            // Reader must be sitting on an object.
            //

            if (reader.TokenClass != JsonTokenClass.Object)
                throw new JsonException("Expecting object.");
            
            reader.Read();
            
            //
            // 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.TokenClass != JsonTokenClass.EndObject)
            {
                string name = reader.ReadMember();
                
                //
                // If the value is an array, then it's a multi-value 
                // entry otherwise a single-value one.
                //

                if (reader.TokenClass == JsonTokenClass.Array)
                {
                    reader.Read();
                    
                    while (reader.TokenClass != JsonTokenClass.EndArray)
                    {
                        collection.Add(name, GetValueAsString(reader));
                        reader.Read();
                    }
                }
                else
                {
                    collection.Add(name, GetValueAsString(reader));    
                }
                
                reader.Read(); // EndArray/String
            }
            
            return ReadReturning(reader, collection);
        }
开发者ID:s7loves,项目名称:pesta,代码行数:59,代码来源:NameValueCollectionImporter.cs

示例2: ImportFromObject

        protected override object ImportFromObject(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);

            reader.Read();
            
            object obj = Activator.CreateInstance(OutputType);
            INonObjectMemberImporter otherImporter = obj as INonObjectMemberImporter;
            
            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();
               
                PropertyDescriptor property = _properties.Find(memberName, true);
                
                //
                // Skip over the member value and continue with reading if
                // the property was not found or if the property found cannot
                // be set.
                //
                
                if (property == null || property.IsReadOnly)
                {
                    if (otherImporter == null || !otherImporter.Import(context, memberName, reader))
                        reader.Skip();
                    continue;
                }
                
                //
                // Check if the property defines a custom import scheme.
                // If yes, ask it to import the value into the property 
                // and then continue with the next.
                //
                
                if (_importers != null)
                {
                    int index = _properties.IndexOf(property);
                    
                    IObjectMemberImporter importer = _importers[index];
                    
                    if (importer != null)
                    {
                        importer.Import(context, reader, obj);
                        continue;
                    }
                }
                    
                //
                // Import from reader based on the property type and 
                // then set the value of the property.
                //
                
                property.SetValue(obj, context.Import(property.PropertyType, reader));
            }
         
            return ReadReturning(reader, obj);
        }
开发者ID:Ghawken,项目名称:FrontView,代码行数:58,代码来源:ComponentImporter.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: ImportFromObject

        protected override object ImportFromObject(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);

            reader.Read();
            
            object o = Activator.CreateInstance(OutputType);
            
            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();
               
                PropertyDescriptor property = _properties.Find(memberName, true);
                
                if (property != null && !property.IsReadOnly)
                    property.SetValue(o, context.Import(property.PropertyType, reader));
                else 
                    reader.Skip();
            }
         
            return ReadReturning(reader, o);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:23,代码来源:ComponentImporter.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: ReadParameters

        private static object ReadParameters(JsonRpcMethod method, JsonReader reader)
        {
            Debug.Assert(method != null);
            Debug.Assert(reader != null);
            
            reader.MoveToContent();
            
            JsonRpcParameter[] parameters = method.GetParameters();
                            
            if (reader.TokenClass == JsonTokenClass.Array)
            {
                reader.Read();
                ArrayList argList = new ArrayList(parameters.Length);
                                
                // TODO: This loop could bomb when more args are supplied that parameters available.
                                                        
                for (int i = 0; i < parameters.Length && reader.TokenClass != JsonTokenClass.EndArray; i++)
                    argList.Add(reader.ReadValue(parameters[i].ParameterType));

                reader.StepOut();
                return argList.ToArray();
            }
            else if (reader.TokenClass == JsonTokenClass.Object)
            {
                reader.Read();
                JsonObject argByName = new JsonObject();
                                
                while (reader.TokenClass != JsonTokenClass.EndObject)
                {
                    // TODO: Imporve this lookup.
                    // FIXME: Does not work when argument is positional.
                                    
                    Type parameterType = null;
                    string name = reader.ReadMember();

                    foreach (JsonRpcParameter parameter in parameters)
                    {
                        if (parameter.Name.Equals(name))
                        {
                            parameterType = parameter.ParameterType;
                            break;
                        }
                    }
                                    
                    argByName.Put(name, reader.ReadValue(parameterType));
                }
                                
                reader.Read();
                return argByName;
            }
            else
            {
                return reader.ReadValue();
            }
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:55,代码来源:JsonRpcDispatcher.cs

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