Newtonsoft.Json.Linq.JProperty.Load C# (CSharp) Method

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
    public static JProperty Load(JsonReader reader)
    {
      if (reader.TokenType == JsonToken.None)
      {
        if (!reader.Read())
          throw new Exception("Error reading JProperty from JsonReader.");
      }
      if (reader.TokenType != JsonToken.PropertyName)
        throw new Exception(
          "Error reading JProperty from JsonReader. Current JsonReader item is not a property: {0}".FormatWith(
            CultureInfo.InvariantCulture, reader.TokenType));

      JProperty p = new JProperty((string)reader.Value);
      p.SetLineInfo(reader as IJsonLineInfo);

      if (!reader.Read())
        throw new Exception("Error reading JProperty from JsonReader.");

      p.ReadContentFrom(reader);

      return p;
    }
  }

Usage Example

Exemplo 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));
 }
All Usage Examples Of Newtonsoft.Json.Linq.JProperty::Load