Load() public static method

Loads an JProperty from a JsonReader.
public static Load ( JsonReader reader ) : JProperty
reader JsonReader A that will be read for the content of the .
return JProperty
Ejemplo n.º 1
0
 public static JToken ReadFrom(JsonReader reader)
 {
     ValidationUtils.ArgumentNotNull(reader, "reader");
     if (reader.TokenType == JsonToken.None && !reader.Read())
     {
         throw new Exception("Error reading JToken from JsonReader.");
     }
     if (reader.TokenType == JsonToken.StartObject)
     {
         return(JObject.Load(reader));
     }
     if (reader.TokenType == JsonToken.StartArray)
     {
         return(JArray.Load(reader));
     }
     if (reader.TokenType == JsonToken.PropertyName)
     {
         return(JProperty.Load(reader));
     }
     if (reader.TokenType == JsonToken.StartConstructor)
     {
         return(JConstructor.Load(reader));
     }
     if (!JsonReader.IsStartToken(reader.TokenType))
     {
         return(new JValue(reader.Value));
     }
     throw new Exception("Error reading JToken from JsonReader. Unexpected token: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
 }
Ejemplo n.º 2
0
 public static JToken ReadFrom(JsonReader reader)
 {
     ValidationUtils.ArgumentNotNull((object)reader, "reader");
     if (reader.TokenType == JsonToken.None && !reader.Read())
     {
         throw JsonReaderException.Create(reader, "Error reading JToken from JsonReader.");
     }
     if (reader.TokenType == JsonToken.StartObject)
     {
         return((JToken)JObject.Load(reader));
     }
     if (reader.TokenType == JsonToken.StartArray)
     {
         return((JToken)JArray.Load(reader));
     }
     if (reader.TokenType == JsonToken.PropertyName)
     {
         return((JToken)JProperty.Load(reader));
     }
     if (reader.TokenType == JsonToken.StartConstructor)
     {
         return((JToken)JConstructor.Load(reader));
     }
     if (!JsonReader.IsStartToken(reader.TokenType))
     {
         return((JToken) new JValue(reader.Value));
     }
     else
     {
         throw JsonReaderException.Create(reader, StringUtils.FormatWith("Error reading JToken from JsonReader. Unexpected token: {0}", (IFormatProvider)CultureInfo.InvariantCulture, (object)reader.TokenType));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a <see cref="JToken"/> from a <see cref="JsonReader"/>.
        /// </summary>
        /// <param name="reader">An <see cref="JsonReader"/> positioned at the token to read into this <see cref="JToken"/>.</param>
        /// <returns>
        /// An <see cref="JToken"/> that contains the token and its descendant tokens
        /// that were read from the reader. The runtime type of the token is determined
        /// by the token type of the first token encountered in the reader.
        /// </returns>
        public static JToken ReadFrom(JsonReader reader)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

            if (reader.TokenType == JsonToken.None)
            {
                if (!reader.Read())
                {
                    throw new Exception("Error reading JToken from JsonReader.");
                }
            }

            if (reader.TokenType == JsonToken.StartObject)
            {
                return(JObject.Load(reader));
            }

            if (reader.TokenType == JsonToken.StartArray)
            {
                return(JArray.Load(reader));
            }

            if (reader.TokenType == JsonToken.PropertyName)
            {
                return(JProperty.Load(reader));
            }

            if (reader.TokenType == JsonToken.StartConstructor)
            {
                return(JConstructor.Load(reader));
            }

            // hack. change to look at TokenType rather than using value
            if (!JsonReader.IsStartToken(reader.TokenType))
            {
                return(new JValue(reader.Value));
            }

            // TODO: loading constructor and parameters?
            throw new Exception("Error reading JToken from JsonReader. Unexpected token: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
        }
Ejemplo n.º 4
0
 // Token: 0x06001588 RID: 5512 RVA: 0x00015E10 File Offset: 0x00014010
 public new static JProperty Load(JsonReader reader)
 {
     return(JProperty.Load(reader, null));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Loads an <see cref="T:Newtonsoft.Json.Linq.JProperty" /> from a <see cref="T:Newtonsoft.Json.JsonReader" />.
 /// </summary>
 /// <param name="reader">A <see cref="T:Newtonsoft.Json.JsonReader" /> that will be read for the content of the <see cref="T:Newtonsoft.Json.Linq.JProperty" />.</param>
 /// <returns>A <see cref="T:Newtonsoft.Json.Linq.JProperty" /> that contains the JSON that was read from the specified <see cref="T:Newtonsoft.Json.JsonReader" />.</returns>
 public static JProperty Load(JsonReader reader)
 {
     return(JProperty.Load(reader, (JsonLoadSettings)null));
 }