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


C# JsonReader.ReadValue方法代码示例

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


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

示例1: GetResultFromJson

        public static object GetResultFromJson(string responseText)
        {
            var jsonReader = new JsonReader(responseText);

            if (responseText == string.Empty) return new JsonObject();

            dynamic result = jsonReader.ReadValue();
            return result;
        }
开发者ID:Huddle,项目名称:dynamicrest,代码行数:9,代码来源:StandardResultBuilder.cs

示例2: while

        object IJsonSerializable.Deserialize(JsonReader reader)
        {
            string property;
            while (reader.ReadProperty(out property))
            {
                switch (property)
                {
                    case "type":
                        Type = reader.ReadValue<string>();
                        break;
                    case "message":
                        Message = reader.ReadValue<string>();
                        break;
                    case "stackTrace":
                        StackTrace = reader.ReadValue<string>();
                        break;
                    case "url":
                        Url = reader.ReadValue<string>();
                        break;
                    case "refererUrl":
                        RefererUrl = reader.ReadValue<string>();
                        break;
                    case "additionalInfo":
                        AdditionalInfo = reader.ReadValue<Dictionary<string, object>>();
                        break;
                    default:
                        throw new ArgumentException("The specified property could not be deserialized.", property);
                }
            }

            return this;
        }
开发者ID:vc3,项目名称:ExoWeb,代码行数:32,代码来源:ServiceError.cs

示例3: JsonReader_Normal

        public void JsonReader_Normal()
        {  
            string json = @"{ name: ""foo"",
description: ""hello me""}";

            using (var jsonReader = new JsonReader(json, false))
            {
                dynamic requestBodyJson = (IDictionary<string, object>)jsonReader.ReadValue();

                Assert.AreEqual("foo", requestBodyJson.name);

                Assert.AreEqual("hello me", requestBodyJson.description);
            }
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:14,代码来源:JsonReaderTests.cs

示例4: TestReadValueObjectEmpty

        public void TestReadValueObjectEmpty()
        {
            var jsonReader = new JsonReader("{}");

            object value = jsonReader.ReadValue();

            Assert.IsTrue(
                value is DynamicDictionary,
                "Value read is not a DynamicDictionary");

            var dictionary = value as DynamicDictionary;

            Assert.AreEqual(0, dictionary.Count);
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:14,代码来源:JsonReaderTests.cs

示例5: JsonReader_InvalidFormat

        public void JsonReader_InvalidFormat()
        {
            string json = "{ name: \"";

            using (var jsonReader = new JsonReader(json, false))
            {
                try
                {
                    jsonReader.ReadValue();
                    Assert.Fail("Expected FormatException to be thrown.");
                }
                catch (FormatException)
                {
                }
            }
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:16,代码来源:JsonReaderTests.cs

示例6: ImportValue

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

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

示例7: JsonReader_EscapedCharacters

        public void JsonReader_EscapedCharacters()
        {
            string json = "{" +
                "\"b\":\"\\b\"," +
                "\"t\":\"\\t\"," +
                "\"n\":\"\\n\"," +
                "\"f\":\"\\f\"," +
                "\"r\":\"\\r\"," +
                "\"q\":\"\\\"\"," +
                "\"rs\":\"\\\\\"" + "}";

            using (var jsonReader = new JsonReader(json, false))
            {
                dynamic requestBodyJson = (IDictionary<string, object>)jsonReader.ReadValue();

                Assert.AreEqual("\b", requestBodyJson.b);
                Assert.AreEqual("\t", requestBodyJson.t);
                Assert.AreEqual("\n", requestBodyJson.n);
                Assert.AreEqual("\f", requestBodyJson.f);
                Assert.AreEqual("\r", requestBodyJson.r);
                Assert.AreEqual("\"", requestBodyJson.q);
                Assert.AreEqual("\\", requestBodyJson.rs);
            }
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:24,代码来源:JsonReaderTests.cs

示例8: TestReadInvalidJsonText

        public void TestReadInvalidJsonText()
        {
            var jsonReader = new JsonReader("klasdjfas89123;kja#!");

            try
            {
                jsonReader.ReadValue();
                Assert.Fail("Expected FormatException to be thrown.");
            }
            catch (FormatException)
            {
            }
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:13,代码来源:JsonReaderTests.cs

示例9: TestReadInvalidJsonTextEmptyString

        public void TestReadInvalidJsonTextEmptyString()
        {
            var jsonReader = new JsonReader("");

            try
            {
                jsonReader.ReadValue();
                Assert.Fail("Expected FormatException to be thrown.");
            }
            catch (FormatException)
            {
            }
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:13,代码来源:JsonReaderTests.cs

示例10: TestReadValueNull

        public void TestReadValueNull()
        {
            var jsonReader = new JsonReader("{ \"data\": null }");

            dynamic value = jsonReader.ReadValue();

            Assert.IsNull(value.data, "Expected Value read to be null");
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:8,代码来源:JsonReaderTests.cs

示例11: TestReadValueBooleanFalse

        public void TestReadValueBooleanFalse()
        {
            var jsonReader = new JsonReader("{ \"data\": false }");

            dynamic value = jsonReader.ReadValue();

            Assert.IsTrue(
                value.data is bool,
                "Value read is not a bool");

            Assert.AreEqual(false, (bool)value.data);
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:12,代码来源:JsonReaderTests.cs

示例12: TestReadValueFloatWithExpentionalNotationNegative

        public void TestReadValueFloatWithExpentionalNotationNegative()
        {
            // ToString and Back loses some fidelity so we do it now
            // to be able to compare the return value from ReadValue
            float min = float.Parse(float.MinValue.ToString());
            var jsonReader = new JsonReader("{ \"data\": " + min.ToString() + " }");

            dynamic value = jsonReader.ReadValue();

            Assert.IsTrue(
                value.data is float,
                "Value read is not a float");

            Assert.AreEqual(min, (float)value.data);
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:15,代码来源:JsonReaderTests.cs

示例13: Deserialize

            public object Deserialize(JsonReader reader)
            {
                string property;
                while (reader.ReadProperty(out property))
                {
                    switch (property)
                    {
                        case "source":
                            Source = reader.ReadValue<ChangeSource>();
                            break;
                        case "changes":
                            Changes = reader.ReadValue<List<ModelEvent>>();
                            break;
                        default:
                            throw new ArgumentException("The specified property could not be deserialized.", property);
                    }
                }

                return this;
            }
开发者ID:vc3,项目名称:ExoWeb,代码行数:20,代码来源:ServiceRequest.cs

示例14: while

            object IJsonSerializable.Deserialize(JsonReader reader)
            {
                ModelInstance instance = null;
                string eventName = null;
                string property;
                Type eventType = null;
                DomainEvent domainEvent = null;
                ModelMethod method = null;
                object[] methodArgs = null;

                while (reader.ReadProperty(out property))
                {
                    switch (property)
                    {
                        // Get the event target
                        case "instance":
                            instance = reader.ReadValue<ModelInstance>();
                            break;

                        // Get the property paths to include
                        case "include":
                            Include = reader.ReadValue<string[]>();
                            break;

                        // Get the type of event
                        case "type":
                            eventName = reader.ReadValue<string>();
                            break;

                        // Get the event data
                        case "event":
                            if (eventName != null && instance != null)
                                eventType = instance.Type.GetEventType(eventName);

                            // Deserialize the strongly-typed event
                            if (eventType != null)
                            {
                                // Create a generic event instance
                                domainEvent = (DomainEvent)typeof(DomainEvent<>)
                                    .MakeGenericType(eventType)
                                    .GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { eventType }, null)
                                    .Invoke(new object[] { reader.ReadValue(eventType) });

                                // Set the event target and inclusion paths
                                domainEvent.Instance = instance;
                                domainEvent.Include = Include;
                            }

                            // Otherwise, see if it is a model method invocation
                            else
                            {
                                var separator = eventName.LastIndexOf(".");
                                if (separator > 0)
                                {
                                    var type = ModelContext.Current.GetModelType(eventName.Substring(0, separator));
                                    var methodName = eventName.Substring(separator + 1);
                                    while (type != null && method == null)
                                    {
                                        method = type.Methods[methodName];
                                        type = type.BaseType;
                                    }

                                    if (method != null && reader.TokenType == Newtonsoft.Json.JsonToken.StartObject && reader.Read())
                                    {
                                        methodArgs = new object[method.Parameters.Count];

                                        string parameter;
                                        while (reader.ReadProperty(out parameter))
                                        {
                                            // Get the parameter with the specified name
                                            var p = method.Parameters.FirstOrDefault(pm => pm.Name == parameter);
                                            if (p == null)
                                                throw new ArgumentException("The parameter '" + property + "' is not valid for method '" + method.DeclaringType.Name + "." + method.Name + "'.");

                                            // Value type
                                            if (p.ReferenceType == null)
                                                methodArgs[p.Index] = reader.ReadValue(p.ParameterType);

                                            // List type
                                            else if (p.IsList)
                                                methodArgs[p.Index] = reader.ReadValue<ModelInstance[]>();

                                            // Reference type
                                            else
                                                methodArgs[p.Index] = reader.ReadValue<ModelInstance>();
                                        }
                                        reader.Read();
                                    }
                                }
                            }
                            break;

                        default:
                            throw new ArgumentException("The specified property could not be deserialized.", property);
                    }
                }

                // Custom domain event
                if (domainEvent != null)
                    return domainEvent;
//.........这里部分代码省略.........
开发者ID:vc3,项目名称:ExoWeb,代码行数:101,代码来源:ServiceRequest.cs

示例15: TestReadValueArrayEmpty

        public void TestReadValueArrayEmpty()
        {
            var jsonReader = new JsonReader("[]");

            object value = jsonReader.ReadValue();

            Assert.IsTrue(
                value is List<object>,
                "Value read is not a List<object>");

            var list = value as List<object>;

            Assert.AreEqual(0, list.Count);
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:14,代码来源:JsonReaderTests.cs


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