-Added JSON Schema implementation
-Move test serialization objects to TestObjects namespace -Fixed JsonConvert to always write a floating point number with a decimal place -Changed Type values to serialize and deserialize to type name string -Fixed JsonWriter to allow objects and arrays to be written in a constructor -Added JsonContainerAttribute with Id, Title and Description members. JsonObject and JsonArray inherit from this attribute -Added JsonArrayAttribute. Has flag to control whether array can contain null items. -Added IsRequired to JsonProperty -Replaced protected method GetSerializableMembers with GetMemberMappings on JsonSerializer -Fixed QuoteChar not getting set when parsing property name -Added Load(JsonReader) to JProperty, JConstructor -Fixed error when populating JProperty with content from collection -Added the ability for JsonTokenWriter to write individual values as well as arrays and objects -Added CreateReader to JToken -Added FromObject to JToken -Added ReadFrom to JToken
This commit is contained in:
@@ -146,7 +146,7 @@ namespace Newtonsoft.Json.Linq
|
||||
if (_parent == null)
|
||||
return null;
|
||||
|
||||
JToken parentNext = ((JToken)_parent.Content)._next;
|
||||
JToken parentNext = _parent.Content._next;
|
||||
JToken parentNextBefore = null;
|
||||
while (parentNext != this)
|
||||
{
|
||||
@@ -736,5 +736,66 @@ namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
get { return this[key]; }
|
||||
}
|
||||
|
||||
public JsonReader CreateReader()
|
||||
{
|
||||
return new JsonTokenReader(this);
|
||||
}
|
||||
|
||||
internal static JToken FromObjectInternal(object o)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(o, "o");
|
||||
|
||||
JsonSerializer jsonSerializer = new JsonSerializer();
|
||||
|
||||
JToken token;
|
||||
using (JsonTokenWriter jsonWriter = new JsonTokenWriter())
|
||||
{
|
||||
jsonSerializer.Serialize(jsonWriter, o);
|
||||
token = jsonWriter.Token;
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="JToken"/> from an object.
|
||||
/// </summary>
|
||||
/// <param name="o">The object that will be used to create <see cref="JToken"/>.</param>
|
||||
/// <returns>A <see cref="JToken"/> with the value of the specified object</returns>
|
||||
public static JToken FromObject(object o)
|
||||
{
|
||||
return FromObjectInternal(o);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user