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


C# JsonReader.Read方法代码示例

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


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

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

示例2: CanDecryptCurrentStringValueAndAccessDecryptedNodes

        public void CanDecryptCurrentStringValueAndAccessDecryptedNodes(string plainTextJson, params JsonNodeType[] expectedNodeTypes)
        {
            var cipherTextJson = @"""" + Convert.ToBase64String(Encoding.UTF8.GetBytes(plainTextJson)) + @"""";

            var info = new JsonSerializeOperationInfo
            {
                EncryptionMechanism = new Base64EncryptionMechanism(),
            };

            var reader = new JsonReader(new StringReader(cipherTextJson), info);
            Assert.That(reader.NodeType, Is.EqualTo(JsonNodeType.None));

            reader.Read("");
            Assert.That(reader.NodeType, Is.EqualTo(JsonNodeType.String));

            reader.SetDecryptReads(true, "");

            foreach (var expectedNodeType in expectedNodeTypes)
            {
                Assert.That(reader.NodeType, Is.EqualTo(expectedNodeType));
                reader.Read("");
            }

            reader.SetDecryptReads(false, "");

            Assert.That(reader.NodeType, Is.EqualTo(JsonNodeType.EndOfString));
        }
开发者ID:QuickenLoans,项目名称:XSerializer,代码行数:27,代码来源:JsonReaderTests.cs

示例3: 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)
        {
            // handle typed datasets
            DataSet ds = (objectType == typeof(DataSet))
                ? new DataSet()
                : (DataSet)Activator.CreateInstance(objectType);

            DataTableConverter converter = new DataTableConverter();

            reader.Read();

            while (reader.TokenType == JsonToken.PropertyName)
            {
                DataTable dt = ds.Tables[(string)reader.Value];
                bool exists = (dt != null);

                dt = (DataTable)converter.ReadJson(reader, typeof(DataTable), dt, serializer);

                if (!exists)
                    ds.Tables.Add(dt);

                reader.Read();
            }

            return ds;
        }
开发者ID:925coder,项目名称:Newtonsoft.Json,代码行数:34,代码来源:DataSetConverter.cs

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

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

示例6: CanReadEachNodeType

        public void CanReadEachNodeType(string json, params JsonNodeType[] expectedNodeTypes)
        {
            var reader = new JsonReader(new StringReader(json), new JsonSerializeOperationInfo());
            Assert.That(reader.NodeType, Is.EqualTo(JsonNodeType.None));

            foreach (var expectedNodeType in expectedNodeTypes)
            {
                reader.Read("");
                Assert.That(reader.NodeType, Is.EqualTo(expectedNodeType));
            }

            reader.Read("");
            Assert.That(reader.NodeType, Is.EqualTo(JsonNodeType.EndOfString));
        }
开发者ID:QuickenLoans,项目名称:XSerializer,代码行数:14,代码来源:JsonReaderTests.cs

示例7: 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>
        internal 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;

            reader.Read();
              }

              reader.Read();

              while (reader.TokenType == JsonToken.StartObject)
              {
            DataRow dr = dt.NewRow();
            reader.Read();

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

              reader.Read();

              if (!dt.Columns.Contains(columnName))
              {
            Type columnType = GetColumnDataType(reader.TokenType);
            dt.Columns.Add(new DataColumn(columnName, columnType));
              }

              dr[columnName] = reader.Value ?? DBNull.Value;
              reader.Read();
            }

            dr.EndEdit();
            dt.Rows.Add(dr);

            reader.Read();
              }

              return dt;
        }
开发者ID:theofanis,项目名称:dotnetwrapper,代码行数:58,代码来源:DataTableConverter.cs

示例8: 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;

                reader.Read();
            }

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

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

                reader.Read();
            }

            return dt;
        }
开发者ID:925coder,项目名称:Newtonsoft.Json,代码行数:39,代码来源:DataTableConverter.cs

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

示例10: ReadJsonHelper

 private static void ReadJsonHelper(string jsonStr)
 {
     var reader = new JsonReader(jsonStr);
     while (reader.Read())
     {
         var tokenType = reader.TokenType;
         switch (tokenType)
         {
             case JsonReader.JsonTokenType.ObjectStart:
             case JsonReader.JsonTokenType.ObjectEnd:
             case JsonReader.JsonTokenType.ArrayStart:
             case JsonReader.JsonTokenType.ArrayEnd:
                 break;
             case JsonReader.JsonTokenType.Property:
                 // ReSharper disable once UnusedVariable
                 var name = reader.GetName();
                 var value = reader.GetValue();
                 break;
             case JsonReader.JsonTokenType.Value:
                 value = reader.GetValue();
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
     }
 }
开发者ID:jango2015,项目名称:corefxlab,代码行数:26,代码来源:PerfSmokeTests.cs

示例11: 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)
    {
      IList<Type> genericArguments = objectType.GetGenericArguments();
      Type keyType = genericArguments[0];
      Type valueType = genericArguments[1];

      reader.Read();
      reader.Read();
      object key = serializer.Deserialize(reader, keyType);
      reader.Read();
      reader.Read();
      object value = serializer.Deserialize(reader, valueType);
      reader.Read();

      return ReflectionUtils.CreateInstance(objectType, key, value);
    }
开发者ID:RecursosOnline,项目名称:c-sharp,代码行数:24,代码来源:KeyValuePairConverter.cs

示例12: CreateJsonObject

        private JsonObject CreateJsonObject(JsonReader reader)
        {
            JsonObject o = new JsonObject();
              string propertyName = null;

              while (reader.Read())
              {
            switch (reader.TokenType)
            {
              case JsonToken.PropertyName:
            propertyName = (string)reader.Value;
            break;
              case JsonToken.EndObject:
            return o;
              case JsonToken.Comment:
            break;
              default:
            IJsonValue propertyValue = CreateJsonValue(reader);
            o.Add(propertyName, propertyValue);
            break;
            }
              }

              throw JsonSerializationException.Create(reader, "Unexpected end.");
        }
开发者ID:SaintLoong,项目名称:AjaxEngine,代码行数:25,代码来源:JsonValueConverter.cs

示例13: 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)
            {
                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));
            }

            long ticks = (long)reader.Value;

            DateTime 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 !NET20
            Type t = (ReflectionUtils.IsNullableType(objectType))
                ? Nullable.GetUnderlyingType(objectType)
                : objectType;
            if (t == typeof(DateTimeOffset))
            {
                return new DateTimeOffset(d);
            }
            #endif

            return d;
        }
开发者ID:cilliemalan,项目名称:Cargo,代码行数:55,代码来源:JavaScriptDateTimeConverter.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 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);

      if (reader.TokenType == JsonToken.Null)
      {
        if (!isNullable)
          throw new Exception("Could not deserialize Null to KeyValuePair.");

        return null;
      }

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

      IList<Type> genericArguments = t.GetGenericArguments();
      Type keyType = genericArguments[0];
      Type valueType = genericArguments[1];

      object key = null;
      object value = null;

      reader.Read();

      while (reader.TokenType == JsonToken.PropertyName)
      {
        switch (reader.Value.ToString())
        {
          case "Key":
            reader.Read();
            key = serializer.Deserialize(reader, keyType);
            break;
          case "Value":
            reader.Read();
            value = serializer.Deserialize(reader, valueType);
            break;
          default:
            reader.Skip();
            break;
        }

        reader.Read();
      }

      return ReflectionUtils.CreateInstance(t, key, value);
    }
开发者ID:techtronics,项目名称:mapreduce-net,代码行数:55,代码来源:KeyValuePairConverter.cs

示例15: JsonReader

    /*function GetVal (jsonString:String,property:String):String

    {

    var reader : JsonReader = new JsonReader(jsonString);

    while (reader.Read())

    {

     if (reader.Token.ToString() == "PropertyName" && reader.Value.ToString() == property )

     {

        reader.Read();

        if (reader.Token.ToString() == "Double" || reader.Token.ToString() == "Int" || reader.Token.ToString() == "String")

            return reader.Value.ToString();

     }

    }

    }*/
    private String[] GetArray(string jsonString, string property)
    {
        string[] array = new string[0];
        int i=0;

        JsonReader reader = new JsonReader(jsonString);

        while (reader.Read())

        {

         if (reader.Token.ToString() == "PropertyName" && reader.Value.ToString() == property )

         {

            reader.Read();

            if (reader.Token.ToString() == "ArrayStart")

            {

                while (reader.Token.ToString() != "ArrayEnd")

                {

                    reader.Read();

                    if (reader.Token.ToString() == "Double" || reader.Token.ToString() == "Int" || reader.Token.ToString() == "String")

                    {

                        array[i++] = reader.Value.ToString();

                    }

                }

            }

            return array;

         }

        }

        return array;
    }
开发者ID:fragallegos,项目名称:USFQ-3D,代码行数:72,代码来源:Gui.cs


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