private static IJsonWrapper ReadValue(WrapperFactory factory,
JsonReader reader)
{
reader.Read();
if (reader.Token == JsonToken.ArrayEnd ||
reader.Token == JsonToken.Null)
{
return(null);
}
IJsonWrapper instance = factory();
if (reader.Token == JsonToken.String)
{
instance.SetString((string)reader.Value);
return(instance);
}
if (reader.Token == JsonToken.Double)
{
instance.SetDouble((double)reader.Value);
return(instance);
}
if (reader.Token == JsonToken.Int)
{
instance.SetInt((int)reader.Value);
return(instance);
}
if (reader.Token == JsonToken.Long)
{
instance.SetLong((long)reader.Value);
return(instance);
}
if (reader.Token == JsonToken.Boolean)
{
instance.SetBoolean((bool)reader.Value);
return(instance);
}
if (reader.Token == JsonToken.ArrayStart)
{
instance.SetJsonType(JsonType.Array);
while (true)
{
IJsonWrapper item = ReadValue(factory, reader);
// nij - added check to see if the item is not null. This is to handle arrays within arrays.
// In those cases when the outer array read the inner array an item was returned back the current
// reader.Token is at the ArrayEnd for the inner array.
if (item == null && reader.Token == JsonToken.ArrayEnd)
{
break;
}
((IList)instance).Add(item);
}
}
else if (reader.Token == JsonToken.ObjectStart)
{
instance.SetJsonType(JsonType.Object);
while (true)
{
reader.Read();
if (reader.Token == JsonToken.ObjectEnd)
{
break;
}
string property = (string)reader.Value;
((IDictionary)instance)[property] = ReadValue(
factory, reader);
}
}
return(instance);
}