• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# JsonReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ImportValue

 protected override object ImportValue(ImportContext context, JsonReader reader)
 {
     if (reader == null)
         throw new ArgumentNullException("reader");
     
     bool value;
     
     if (reader.TokenClass == JsonTokenClass.Number)
     {
         try
         {
             value = Convert.ToInt64(reader.Text, CultureInfo.InvariantCulture) != 0;
         }
         catch (FormatException e)
         {
             throw new JsonException(string.Format("The JSON Number {0} must be an integer to be convertible to System.Boolean.", reader.Text), e);
         }
     }
     else if (reader.TokenClass == JsonTokenClass.Boolean)
     {
         value = reader.Text == JsonBoolean.TrueText;
     }
     else
     {
         throw new JsonException(string.Format("Found {0} where expecting a JSON Boolean.", reader.TokenClass));
     }
     
     return value ? BooleanObject.True : BooleanObject.False;
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:29,代码来源:BooleanImporter.cs


示例2: ReadJson

 /// <summary>
 /// Reads the JSON representation of the object.
 /// </summary>
 /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
 /// <param name="objectType">Type of the object.</param>
 /// <param name="existingValue">The existing property value of the JSON that is being converted.</param>
 /// <param name="serializer">The calling serializer.</param>
 /// <returns>The object value.</returns>
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     if (reader.TokenType == JsonToken.Null)
     {
         return null;
     }
     else
     {
         if (reader.TokenType == JsonToken.String)
         {
             try
             {
                 Version v = new Version((string)reader.Value);
                 return v;
             }
             catch (Exception ex)
             {
                 throw JsonSerializationException.Create(reader, "Error parsing version string: {0}".FormatWith(CultureInfo.InvariantCulture, reader.Value), ex);
             }
         }
         else
         {
             throw JsonSerializationException.Create(reader, "Unexpected token or value when parsing version. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value));
         }
     }
 }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:34,代码来源:VersionConverter.cs


示例3: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            NameContainer nameContainer = new NameContainer();
            nameContainer.Value = (string)reader.Value;

            return nameContainer;
        }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:7,代码来源:NameContainerConverter.cs


示例4: ReadAndAssertProperty

    private static void ReadAndAssertProperty(JsonReader reader, string propertyName)
    {
      ReadAndAssert(reader);

      if (reader.TokenType != JsonToken.PropertyName || reader.Value.ToString() != propertyName)
        throw new JsonSerializationException("Expected JSON property '{0}'.".FormatWith(CultureInfo.InvariantCulture, propertyName));
    }
开发者ID:Gert-Cominotto,项目名称:MvvmCross,代码行数:7,代码来源:EntityKeyMemberConverter.cs


示例5: ReadJson

 // Token: 0x06000685 RID: 1669
 // RVA: 0x0003758C File Offset: 0x0003578C
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     if (reader.TokenType == JsonToken.Null)
     {
         if (!ReflectionUtils.IsNullable(objectType))
         {
             throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Cannot convert null value to {0}.", CultureInfo.InvariantCulture, objectType));
         }
         return null;
     }
     else
     {
         if (reader.TokenType != JsonToken.StartConstructor || !string.Equals(reader.Value.ToString(), "Date", StringComparison.Ordinal))
         {
             throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token or value when parsing date. Token: {0}, Value: {1}", CultureInfo.InvariantCulture, reader.TokenType, reader.Value));
         }
         reader.Read();
         if (reader.TokenType != JsonToken.Integer)
         {
             throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token parsing date. Expected Integer, got {0}.", CultureInfo.InvariantCulture, reader.TokenType));
         }
         long javaScriptTicks = (long)reader.Value;
         DateTime dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(javaScriptTicks);
         reader.Read();
         if (reader.TokenType != JsonToken.EndConstructor)
         {
             throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token parsing date. Expected EndConstructor, got {0}.", CultureInfo.InvariantCulture, reader.TokenType));
         }
         return dateTime;
     }
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:33,代码来源:JavaScriptDateTimeConverter.cs


示例6: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            DataTable dt = existingValue as DataTable;

            if (dt == null)
            {
                // handle typed datasets
                dt = (objectType == typeof(DataTable))
                    ? new DataTable()
                    : (DataTable)Activator.CreateInstance(objectType);
            }

            if (reader.TokenType == JsonToken.PropertyName)
            {
                dt.TableName = (string)reader.Value;

                CheckedRead(reader);
            }

            if (reader.TokenType != JsonToken.StartArray)
                throw JsonSerializationException.Create(reader, "Unexpected JSON token when reading DataTable. Expected StartArray, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));

            CheckedRead(reader);

            while (reader.TokenType != JsonToken.EndArray)
            {
                CreateRow(reader, dt);

                CheckedRead(reader);
            }

            return dt;
        }
开发者ID:jrwren,项目名称:yahoofinance,代码行数:41,代码来源:DataTableConverter.cs


示例7: ReadJson

            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                User user = new User();
                user.UserName = (string)reader.Value;

                return user;
            }
开发者ID:GorelH,项目名称:ravendb,代码行数:7,代码来源:JsonConverterAttributeClass.cs


示例8: DeserializeNode

        private void DeserializeNode(JsonReader reader, XmlDocument document, XmlNamespaceManager manager, XmlNode currentNode)
        {
            do
              {
            switch (reader.TokenType)
            {
              case JsonToken.PropertyName:
            string propertyName = reader.Value.ToString();
            reader.Read();

            if (reader.TokenType == JsonToken.StartArray)
            {
              while (reader.Read() && reader.TokenType != JsonToken.EndArray)
              {
                DeserializeValue(reader, document, manager, propertyName, currentNode);
              }
            }
            else
            {
              DeserializeValue(reader, document, manager, propertyName, currentNode);
            }
            break;
              //case JsonToken.String:
              //    DeserializeValue(reader, document, manager, TextName, currentNode);
              //    break;
              case JsonToken.EndObject:
              case JsonToken.EndArray:
            return;
              default:
            throw new JsonSerializationException("Unexpected JsonToken when deserializing node: " + reader.TokenType);
            }
              } while (reader.TokenType == JsonToken.PropertyName || reader.Read());
              // don't read if current token is a property. token was already read when parsing element attributes
        }
开发者ID:chrisfay,项目名称:EnvatoTracker,代码行数:34,代码来源:XmlNodeConverter.cs


示例9: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType)
        {
            Type t = (ReflectionUtils.IsNullableType(objectType))
            ? Nullable.GetUnderlyingType(objectType)
            : objectType;

              if (reader.TokenType == JsonToken.Null)
              {
            if (!ReflectionUtils.IsNullable(objectType))
              throw new Exception("Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));

            return null;
              }

              if (reader.TokenType != JsonToken.String)
            throw new Exception("Unexpected token parsing binary. Expected String, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));

              string encodedData = reader.Value.ToString();

              byte[] data = Convert.FromBase64String(encodedData);

              if (t == typeof(byte[]))
            return data;

            #if !SILVERLIGHT && !PocketPC
              if (typeof(Binary).IsAssignableFrom(t))
            return new Binary(data);
            #endif
            #if !SILVERLIGHT
              if (typeof(SqlBinary).IsAssignableFrom(t))
            return new SqlBinary(data);
            #endif
              throw new Exception("Unexpected object type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, objectType));
        }
开发者ID:jabbo,项目名称:Jabbo,代码行数:40,代码来源:BinaryConverter.cs


示例10: ReadJson

 // Token: 0x06000181 RID: 385
 // RVA: 0x0002B488 File Offset: 0x00029688
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     Type type = ReflectionUtils.IsNullableType(objectType) ? Nullable.GetUnderlyingType(objectType) : objectType;
     if (reader.TokenType == JsonToken.Null)
     {
         if (!ReflectionUtils.IsNullable(objectType))
         {
             throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Cannot convert null value to {0}.", CultureInfo.InvariantCulture, objectType));
         }
         return null;
     }
     else
     {
         byte[] value;
         if (reader.TokenType == JsonToken.StartArray)
         {
             value = this.ReadByteArray(reader);
         }
         else
         {
             if (reader.TokenType != JsonToken.String)
             {
                 throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected token parsing binary. Expected String or StartArray, got {0}.", CultureInfo.InvariantCulture, reader.TokenType));
             }
             string s = reader.Value.ToString();
             value = Convert.FromBase64String(s);
         }
         if (type == typeof(SqlBinary))
         {
             return new SqlBinary(value);
         }
         throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unexpected object type when writing binary: {0}", CultureInfo.InvariantCulture, objectType));
     }
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:36,代码来源:BinaryConverter.cs


示例11: Read

 public override object Read(JsonReader reader)
 {
     var p = (EnumerableProperty)base.Read(reader);
     var length = int.Parse(reader.ReadProperty().Value.ToString());
     p.Length = length;
     return p;
 }
开发者ID:sethjuarez,项目名称:numl,代码行数:7,代码来源:EnumerablePropertySerializer.cs


示例12: ReadAndAssertProperty

        private static void ReadAndAssertProperty(JsonReader reader, string propertyName)
        {
            ReadAndAssert(reader);

            if (reader.TokenType != JsonToken.PropertyName || !string.Equals(reader.Value.ToString(), propertyName, StringComparison.OrdinalIgnoreCase))
                throw new JsonSerializationException("Expected JSON property '{0}'.".FormatWith(CultureInfo.InvariantCulture, propertyName));
        }
开发者ID:sat1582,项目名称:CODEFramework,代码行数:7,代码来源:EntityKeyMemberConverter.cs


示例13: Populate

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

              Type objectType = target.GetType();

              JsonContract contract = _serializer.ContractResolver.ResolveContract(objectType);

              if (reader.TokenType == JsonToken.None)
            reader.Read();

              if (reader.TokenType == JsonToken.StartArray)
              {
            PopulateList(CollectionUtils.CreateCollectionWrapper(target), reader, null, GetArrayContract(objectType));
              }
              else if (reader.TokenType == JsonToken.StartObject)
              {
            CheckedRead(reader);

            string id = null;
            if (reader.TokenType == JsonToken.PropertyName && string.Equals(reader.Value.ToString(), JsonTypeReflector.IdPropertyName, StringComparison.Ordinal))
            {
              CheckedRead(reader);
              id = reader.Value.ToString();
              CheckedRead(reader);
            }

            if (contract is JsonDictionaryContract)
              PopulateDictionary(CollectionUtils.CreateDictionaryWrapper(target), reader, (JsonDictionaryContract) contract, id);
            else if (contract is JsonObjectContract)
              PopulateObject(target, reader, (JsonObjectContract) contract, id);
            else
              throw new Exception("dfsdfsdf");
              }
        }
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:35,代码来源:JsonSerializerReader.cs


示例14: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing property value of the JSON that is being converted.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var t = (ReflectionUtils.IsNullableType(objectType)) ? Nullable.GetUnderlyingType(objectType) : objectType;

            if (reader.TokenType == JsonToken.Null)
            {
                if (!ReflectionUtils.IsNullable(objectType))
                    throw JsonSerializationException.Create(reader, "Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));

                return null;
            }

            if (reader.TokenType != JsonToken.StartConstructor || !string.Equals(reader.Value.ToString(), "Date", StringComparison.Ordinal))
                throw JsonSerializationException.Create(reader, "Unexpected token or value when parsing date. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value));

            reader.Read();

            if (reader.TokenType != JsonToken.Integer)
                throw JsonSerializationException.Create(reader, "Unexpected token parsing date. Expected Integer, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));

            var ticks = (long)reader.Value;

            var d = DateTimeUtils.ConvertJavaScriptTicksToDateTime(ticks);

            reader.Read();

            if (reader.TokenType != JsonToken.EndConstructor)
                throw JsonSerializationException.Create(reader, "Unexpected token parsing date. Expected EndConstructor, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));

            if (t == typeof(DateTimeOffset))
                return new DateTimeOffset(d);

            return d;
        }
开发者ID:sat1582,项目名称:CODEFramework,代码行数:42,代码来源:JavaScriptDateTimeConverter.cs


示例15: ImportFromNumber

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

            string text = reader.Text;

            double time;

            try
            {
                time = Convert.ToDouble(text, CultureInfo.InvariantCulture);
            }
            catch (FormatException e)
            {
                throw NumberError(e, text);
            }
            catch (OverflowException e)
            {
                throw NumberError(e, text);
            }

            try
            {
                return ReadReturning(reader, UnixTime.ToDateTime(time));
            }
            catch (ArgumentException e)
            {
                throw NumberError(e, text);
            }
        }
开发者ID:atifaziz,项目名称:Jayrock,代码行数:31,代码来源:DateTimeImporter.cs


示例16: onReqStrenSuccess

 private void onReqStrenSuccess(BaseWWWRequest obj)
 {
     try
     {
         StrengthenData data = new JsonReader().Read<StrengthenData>(base.UTF8String);
         base.responseData = data;
         if (data.eid != 0)
         {
             this.onReqStrenFail(obj);
         }
         else
         {
             if (data.shipVO != null)
             {
                 GameData.instance.UpdateUserShip(data.shipVO);
             }
             this.DeleteMaterials();
             if (data.detailInfo != null)
             {
                 GameData.instance.UserInfo.UpdateDetailInfo(data.detailInfo);
             }
             if (data.equipmentVo != null)
             {
                 GameData.instance.SetUserEquipments(data.equipmentVo);
             }
             this.OnStrengthenSuccess(EventArgs.Empty);
         }
     }
     catch (Exception exception)
     {
         z.log(exception.Message);
         this.onReqStrenFail(obj);
     }
 }
开发者ID:lavender1213,项目名称:ShipGirlBot,代码行数:34,代码来源:ReqStrengthen.cs


示例17: ImportFromBoolean

 protected override object ImportFromBoolean(ImportContext context, JsonReader reader)
 {
     Debug.Assert(context != null);
     Debug.Assert(reader != null);
     
     return BooleanObject.Box(reader.ReadBoolean());
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:7,代码来源:BooleanImporter.cs


示例18: ReadJson

        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            bool isNullable = ReflectionUtils.IsNullableType(objectType);

            Type t = (isNullable)
                         ? Nullable.GetUnderlyingType(objectType)
                         : objectType;

            ReflectionObject reflectionObject = ReflectionObjectPerType.Get(t);

            if (reader.TokenType == JsonToken.Null)
            {
                if (!isNullable)
                    throw JsonSerializationException.Create(reader, "Cannot convert null value to Matrix4x4.");

                return null;
            }

            object[] values = new object[PropNames.Length];

            ReadAndAssert(reader);

            while (reader.TokenType == JsonToken.PropertyName)
            {
                string propertyName = reader.Value.ToString();

                var index = Array.IndexOf(PropNames, propertyName);
                if (index != -1)
                {
                    var name = PropNames[index];
                    ReadAndAssert(reader);
                    values[index] = serializer.Deserialize(reader, reflectionObject.GetType(name));
                }
                else
                {
                    reader.Skip();
                }

                ReadAndAssert(reader);
            }

            var matrix = (Matrix4x4)reflectionObject.Creator();
            matrix.m00 = (float)values[0];
            matrix.m01 = (float)values[1];
            matrix.m02 = (float)values[2];
            matrix.m03 = (float)values[3];
            matrix.m10 = (float)values[4];
            matrix.m11 = (float)values[5];
            matrix.m12 = (float)values[6];
            matrix.m13 = (float)values[7];
            matrix.m20 = (float)values[8];
            matrix.m21 = (float)values[9];
            matrix.m22 = (float)values[10];
            matrix.m23 = (float)values[11];
            matrix.m30 = (float)values[12];
            matrix.m31 = (float)values[13];
            matrix.m32 = (float)values[14];
            matrix.m33 = (float)values[15];
            return matrix;
        }
开发者ID:createdbyx,项目名称:Newtonsoft.Json,代码行数:68,代码来源:Matrix4x4Converter.cs


示例19: GetJsonValueInt

    public static int GetJsonValueInt(string data, string key)
    {
        try
        {
#if !UNITY_IOS
            //iOS build 에서는 안통하는 코드 
            JsonData jdata = JsonMapper.ToObject(data);
            return int.Parse(jdata[key].ToString());
#else
			//iOS android 에서 다 통하는 코드 
			JsonReader reader = new JsonReader (data);
			
			while (reader.Read()) 
			{
				
				if (reader.Token.ToString () == "PropertyName" && 
				    reader.Value.ToString () == key) 
				{
					reader.Read ();
					return int.Parse(reader.Value.ToString ());				
				}			
				
			}
#endif
        }
        catch
        {
            UnityEngine.Debug.LogWarning("json parsing error : " + data);
        }
        return -1;
    }
开发者ID:kimha578,项目名称:jwUnityStudy,代码行数:31,代码来源:Util.cs


示例20: ArgumentException

        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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JsonReader.JsonTokenizer类代码示例发布时间:2022-05-24
下一篇:
C# JsonPropertyCollection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap