本文整理汇总了C#中Newtonsoft.Json.JsonReader.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.Skip方法的具体用法?C# JsonReader.Skip怎么用?C# JsonReader.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.Skip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJson
/// <summary>
/// Reads the JSON representation of the object.
/// </summary>
public sealed override object ReadJson(
JsonReader reader,
Type objectType,
[AllowNull] object existingValue,
JsonSerializer serializer)
{
if (reader.TokenType != JsonToken.StartObject)
{
return DeserializeLiteral(reader, objectType, serializer);
}
object value = null;
while (reader.TokenType != JsonToken.EndObject)
{
reader.Read();
if (reader.TokenType == JsonToken.PropertyName && Equals(reader.Value, "@value"))
{
reader.Read();
value = DeserializeLiteral(reader, objectType, serializer);
}
else
{
reader.Skip();
}
}
return value;
}
示例2: ReadJsonAsStringArray
protected virtual object ReadJsonAsStringArray(JsonReader reader)
{
if (reader.TokenType != JsonToken.StartArray)
{
reader.Skip();
return null;
}
var rowValues = new List<string>();
var valueStartDepth = reader.Depth;
var sb = new StringBuilder();
using (var sw = new StringWriter(sb))
{
using (var jw = new JsonTextWriter(sw))
{
while (reader.Read() && !(reader.TokenType == JsonToken.EndArray && reader.Depth == valueStartDepth))
{
jw.WriteToken(reader, true);
rowValues.Add(sb.ToString());
sb.Clear();
}
}
}
return rowValues.ToArray();
}
示例3: DeserializeFromPackageJson
public static DubProjectConfiguration DeserializeFromPackageJson(JsonReader j)
{
var c = new DubProjectConfiguration { Name = "<Undefined>" };
var srz = new JsonSerializer();
while (j.Read() && j.TokenType != JsonToken.EndObject)
{
if (j.TokenType == JsonToken.PropertyName)
{
switch (j.Value as string)
{
case "name":
c.Name = c.Id = j.ReadAsString();
break;
case "platforms":
j.Read();
c.Platform = string.Join("|",srz.Deserialize<string[]>(j));
break;
default:
if (!c.BuildSettings.TryDeserializeBuildSetting(j))
j.Skip();
break;
}
}
}
return c;
}
示例4: ReadAsObjectArray
protected virtual object[] ReadAsObjectArray(JsonReader reader)
{
if (reader.TokenType != JsonToken.StartArray)
{
reader.Skip();
return null;
}
var rowValues = new List<object>();
var valueStartDepth = reader.Depth;
while (reader.Read() && !(reader.TokenType == JsonToken.EndArray && reader.Depth == valueStartDepth))
{
rowValues.Add(reader.Value);
}
return rowValues.ToArray();
}
示例5: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
bool flag = ReflectionUtils.IsNullableType(objectType);
if (reader.TokenType == JsonToken.Null)
{
if (!flag)
throw JsonSerializationException.Create(reader, "Cannot convert null value to KeyValuePair.");
else
return (object) null;
}
else
{
Type type = flag ? Nullable.GetUnderlyingType(objectType) : objectType;
IList<Type> list = (IList<Type>) type.GetGenericArguments();
Type objectType1 = list[0];
Type objectType2 = list[1];
object obj1 = (object) null;
object obj2 = (object) null;
reader.Read();
while (reader.TokenType == JsonToken.PropertyName)
{
string a = reader.Value.ToString();
if (string.Equals(a, "Key", StringComparison.OrdinalIgnoreCase))
{
reader.Read();
obj1 = serializer.Deserialize(reader, objectType1);
}
else if (string.Equals(a, "Value", StringComparison.OrdinalIgnoreCase))
{
reader.Read();
obj2 = serializer.Deserialize(reader, objectType2);
}
else
reader.Skip();
reader.Read();
}
return ReflectionUtils.CreateInstance(type, obj1, obj2);
}
}
示例6: Deserialize
public async Task<ISingleResourceDocument> Deserialize(JsonReader reader, string currentPath)
{
if (reader.TokenType != JsonToken.StartObject)
throw new DeserializationException("Invalid document root", "Document root is not an object!", currentPath);
IResourceObject primaryData = null;
IMetadata metadata = null;
while (reader.Read())
{
if (reader.TokenType != JsonToken.PropertyName) break;
// Has to be a property name
var propertyName = (string)reader.Value;
reader.Read();
switch (propertyName)
{
case RelatedDataKeyName:
// TODO: If we want to capture related resources, this would be the place to do it
reader.Skip();
break;
case PrimaryDataKeyName:
primaryData = await DeserializePrimaryData(reader, currentPath + "/" + PrimaryDataKeyName);
break;
case MetaKeyName:
metadata = await _metadataFormatter.Deserialize(reader, currentPath + "/" + MetaKeyName);
break;
default:
reader.Skip();
break;
}
}
return new SingleResourceDocument(primaryData, new IResourceObject[] { }, metadata);
}
示例7: CalculatePropertyDetails
private bool CalculatePropertyDetails(JsonProperty property, ref JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, object target, out bool useExistingValue, out object currentValue, out JsonContract propertyContract, out bool gottenCurrentValue)
{
currentValue = (object) null;
useExistingValue = false;
propertyContract = (JsonContract) null;
gottenCurrentValue = false;
if (property.Ignored)
{
reader.Skip();
return true;
}
else
{
switch (property.ObjectCreationHandling.GetValueOrDefault(this.Serializer.ObjectCreationHandling))
{
case ObjectCreationHandling.Auto:
case ObjectCreationHandling.Reuse:
if ((reader.TokenType == JsonToken.StartArray || reader.TokenType == JsonToken.StartObject) && property.Readable)
{
currentValue = property.ValueProvider.GetValue(target);
gottenCurrentValue = true;
useExistingValue = currentValue != null && !property.PropertyType.IsArray && !ReflectionUtils.InheritsGenericDefinition(property.PropertyType, typeof (ReadOnlyCollection<>)) && !TypeExtensions.IsValueType(property.PropertyType);
break;
}
else
break;
}
if (!property.Writable && !useExistingValue)
{
reader.Skip();
return true;
}
else if (property.NullValueHandling.GetValueOrDefault(this.Serializer.NullValueHandling) == NullValueHandling.Ignore && reader.TokenType == JsonToken.Null)
{
reader.Skip();
return true;
}
else if (this.HasFlag(property.DefaultValueHandling.GetValueOrDefault(this.Serializer.DefaultValueHandling), DefaultValueHandling.Ignore) && JsonReader.IsPrimitiveToken(reader.TokenType) && MiscellaneousUtils.ValueEquals(reader.Value, property.GetResolvedDefaultValue()))
{
reader.Skip();
return true;
}
else
{
if (property.PropertyContract == null)
property.PropertyContract = this.GetContractSafe(property.PropertyType);
if (currentValue == null)
{
propertyContract = property.PropertyContract;
}
else
{
propertyContract = this.GetContractSafe(currentValue.GetType());
if (propertyContract != property.PropertyContract)
propertyConverter = this.GetConverter(propertyContract, property.MemberConverter, containerContract, containerProperty);
}
return false;
}
}
}
示例8: HandleError
private void HandleError(JsonReader reader, bool readPastError, int initialDepth)
{
this.ClearErrorContext();
if (!readPastError)
return;
reader.Skip();
do
;
while (reader.Depth > initialDepth + 1 && reader.Read());
}
示例9: Deserialize
private object Deserialize(Type objectType, JsonReader reader, object obj = null)
{
object retval = obj == null ? Activator.CreateInstance(objectType) : obj;
if (reader.TokenType != JsonToken.StartObject) throw new JsonReaderException(String.Format("Expected JsonToken.StartObject, got {0}", reader.TokenType.ToString()));
reader.Read(); // Burn the StartObject token
do
{
if (reader.TokenType == JsonToken.PropertyName)
{
string value = (string)reader.Value;
var modelProperty = _modelManager.GetPropertyForJsonKey(objectType, value);
if (value == RelationshipsKeyName)
{
// This can only happen within a links object
reader.Read(); // burn the PropertyName token
//TODO: linked resources (Done??)
DeserializeLinkedResources(retval, reader);
}
else if (value == AttributesKeyName) {
reader.Read();
retval = Deserialize(objectType, reader, retval);
}
else if (modelProperty != null)
{
if (!(modelProperty is FieldModelProperty))
{
reader.Read(); // burn the PropertyName token
//TODO: Embedded would be dropped here!
continue; // These aren't supposed to be here, they're supposed to be in "related"!
}
var prop = modelProperty.Property;
object propVal;
Type enumType;
if (prop.PropertyType == typeof(string) &&
prop.GetCustomAttributes().Any(attr => attr is SerializeStringAsRawJsonAttribute))
{
reader.Read();
if (reader.TokenType == JsonToken.Null)
{
propVal = null;
}
else
{
var token = JToken.Load(reader);
var rawPropVal = token.ToString();
propVal = JsonHelpers.MinifyJson(rawPropVal);
}
}
else if (prop.PropertyType.IsGenericType &&
prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
(enumType = prop.PropertyType.GetGenericArguments()[0]).IsEnum)
{
// Nullable enums need special handling
reader.Read();
propVal = reader.TokenType == JsonToken.Null
? null
: Enum.Parse(enumType, reader.Value.ToString());
}
else if (prop.PropertyType == typeof(DateTimeOffset) ||
prop.PropertyType == typeof(DateTimeOffset?))
{
// For some reason
reader.ReadAsString();
propVal = reader.TokenType == JsonToken.Null
? (object) null
: DateTimeOffset.Parse(reader.Value.ToString());
}
else
{
reader.Read();
propVal = DeserializeAttribute(prop.PropertyType, reader);
}
prop.SetValue(retval, propVal, null);
// Tell the MetadataManager that we deserialized this property
MetadataManager.Instance.SetMetaForProperty(retval, prop, true);
// pop the value off the reader, so we catch the EndObject token below!.
reader.Read();
}
else
{
// Unexpected/unknown property--Skip the propertyname and its value
reader.Skip();
if (reader.TokenType == JsonToken.StartArray || reader.TokenType == JsonToken.StartObject) reader.Skip();
else reader.Read();
}
}
} while (reader.TokenType != JsonToken.EndObject);
reader.Read(); // burn the EndObject token before returning back up the call stack
return retval;
//.........这里部分代码省略.........
示例10: TryPopulateProperty
public bool TryPopulateProperty(string propName, JsonReader j, IProgressMonitor monitor)
{
switch (propName.ToLowerInvariant())
{
case "displayname":
displayName = j.ReadAsString ();
break;
case "name":
packageName = j.ReadAsString();
break;
case "description":
Description = j.ReadAsString();
break;
case "copyright":
Copyright = j.ReadAsString();
break;
case "homepage":
Homepage = j.ReadAsString();
break;
case "authors":
if (!j.Read() || j.TokenType != JsonToken.StartArray)
throw new JsonReaderException("Expected [ when parsing Authors");
authors.Clear();
while (j.Read() && j.TokenType != JsonToken.EndArray)
if (j.TokenType == JsonToken.String)
authors.Add(j.Value as string);
break;
case "dependencies":
if (!j.Read () || j.TokenType != JsonToken.StartObject)
throw new JsonReaderException ("Expected { when parsing Authors");
DubReferences.DeserializeDubPrjDependencies(j, monitor);
break;
case "configurations":
if (!j.Read() || j.TokenType != JsonToken.StartArray)
throw new JsonReaderException("Expected [ when parsing Configurations");
if(ParentSolution != null && ParentSolution.Configurations.Count == 1 && ParentSolution.Configurations[0].Id == DubProjectConfiguration.DefaultConfigId)
ParentSolution.Configurations.Clear();
if(Configurations.Count == 1 && Configurations[0].Id == DubProjectConfiguration.DefaultConfigId)
Configurations.Clear();
while (j.Read() && j.TokenType != JsonToken.EndArray)
AddProjectAndSolutionConfiguration(DubProjectConfiguration.DeserializeFromPackageJson(j));
break;
case "subpackages":
if (!j.Read () || j.TokenType != JsonToken.StartArray)
throw new JsonReaderException ("Expected [ when parsing subpackages");
while (j.Read () && j.TokenType != JsonToken.EndArray)
DubSubPackage.ReadAndAdd (this, j, monitor);
break;
case "buildtypes":
if (!j.Read() || j.TokenType != JsonToken.StartObject)
throw new JsonReaderException("Expected [ when parsing build types");
while (j.Read() && j.TokenType != JsonToken.EndObject)
{
var n = j.Value as string;
if (!buildTypes.Contains(n))
buildTypes.Add(n);
j.Skip();
}
buildTypes.Sort();
break;
default:
return CommonBuildSettings.TryDeserializeBuildSetting(j);
}
return true;
}
示例11: GetNumberOfActionDependentExamples
/// <summary>
/// Returns the number of action dependent examples found within <paramref name="reader"/>.
/// </summary>
/// <param name="reader">The JSON.</param>
/// <param name="multiProperty">The optional multi property name.</param>
/// <returns>Returns the number of action dependent examples.</returns>
public static int GetNumberOfActionDependentExamples(JsonReader reader, string multiProperty = PropertyConfiguration.MultiPropertyDefault)
{
// handle the case when the reader is already positioned at JsonToken.StartObject
if (reader.TokenType == JsonToken.None && !reader.Read())
throw new VowpalWabbitJsonException(reader, "Expected non-empty JSON");
if (reader.TokenType != JsonToken.StartObject)
throw new VowpalWabbitJsonException(reader, "Expected start object");
while (reader.Read())
{
if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == multiProperty))
{
reader.Skip();
continue;
}
if (!reader.Read() || reader.TokenType != JsonToken.StartArray)
throw new VowpalWabbitJsonException(reader, "Expected start arrray");
var exampleCount = 0;
while(reader.Read() && reader.TokenType != JsonToken.EndArray)
{
exampleCount++;
reader.Skip();
}
return exampleCount;
}
return 0;
}
示例12: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var depth = reader.Depth;
string[] columns = null;
var contract = (JsonArrayContract)serializer.ContractResolver.ResolveContract(objectType);
object ret = existingValue;
while (reader.Read() && reader.TokenType != JsonToken.EndObject && reader.Depth > depth)
{
while (reader.TokenType == JsonToken.PropertyName)
{
var prop = (string)reader.Value;
if (prop == "columns")
{
reader.Read();
columns = serializer.Deserialize<string[]>(reader);
}
else if (prop == "data")
{
if (columns == null || columns.Length == 0)
{
reader.Skip();
}
else
{
//Deserialize the data part
if (existingValue == null)
{
if (contract.DefaultCreator != null)
{
ret = contract.DefaultCreator();
}
else
{
ret = Activator.CreateInstance(objectType);
}
}
var collectionItemType = contract.CollectionItemType;
var lst = (IList) ret;
if (!(reader.Read() && reader.TokenType == JsonToken.StartArray))
{
throw new Exception("Expected to read an array");
}
int arrayDepth = reader.Depth;
while (reader.Read() && (reader.TokenType != JsonToken.EndArray && reader.Depth >= arrayDepth))
{
//This is a row
var item = new JObject();
if (reader.TokenType != JsonToken.StartArray)
throw new Exception("Expected to read an array but found " + reader.TokenType.ToString());
int index = 0;
int arrayDepth2 = reader.Depth;
while (reader.Read() &&
(reader.TokenType != JsonToken.EndArray && reader.Depth >= arrayDepth2))
{
item[columns[index]] = JToken.ReadFrom(reader);
index++;
}
using (var subReader = item.CreateReader())
{
lst.Add(serializer.Deserialize(subReader, collectionItemType));
}
}
if (reader.Depth > arrayDepth)
throw new JsonReaderException("Unexpected end of content while reading array.");
}
}
else
{
reader.Skip();
}
}
}
return ret;
}
示例13: SetObjectMember
private void SetObjectMember(JsonReader reader, object target, Type targetType, string memberName)
{
if (!reader.Read())
throw new JsonSerializationException("Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));
MemberMappingCollection memberMappings = GetMemberMappings(targetType);
Type memberType;
object value;
// test if a member with memberName exists on the type
// otherwise test if target is a dictionary and assign value with the key if it is
if (memberMappings.Contains(memberName))
{
MemberMapping memberMapping = memberMappings[memberName];
if (memberMapping.Ignored)
{
reader.Skip();
return;
}
// get the member's underlying type
memberType = ReflectionUtils.GetMemberUnderlyingType(memberMapping.Member);
object currentValue = ReflectionUtils.GetMemberValue(memberMapping.Member, target);
bool useExistingValue = (currentValue != null
&& (_objectCreationHandling == ObjectCreationHandling.Auto || _objectCreationHandling == ObjectCreationHandling.Reuse)
&& (reader.TokenType == JsonToken.StartArray || reader.TokenType == JsonToken.StartObject)
&& (!memberType.IsArray && !ReflectionUtils.IsSubClass(memberType, typeof(ReadOnlyCollection<>))));
if (!memberMapping.Writable && !useExistingValue)
{
reader.Skip();
return;
}
value = CreateObject(reader, memberType, (useExistingValue) ? currentValue : null);
if (_nullValueHandling == NullValueHandling.Ignore && value == null)
return;
if (!useExistingValue)
ReflectionUtils.SetMemberValue(memberMapping.Member, target, value);
}
else
{
if (_missingMemberHandling == MissingMemberHandling.Error)
throw new JsonSerializationException("Could not find member '{0}' on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, memberName, targetType.GetType().Name));
}
}
示例14: ReadItem
private static KeyValuePair<string, string> ReadItem(JsonReader reader, JsonSerializer serializer)
{
string key = null;
string value = null;
ReadAndAssert(reader);
while (reader.TokenType == JsonToken.PropertyName)
{
string propertyName = reader.Value.ToString();
if (string.Equals(propertyName, "opt_name", StringComparison.OrdinalIgnoreCase))
{
ReadAndAssert(reader);
key = serializer.Deserialize<string>(reader);
}
else if (string.Equals(propertyName, "opt_value", StringComparison.OrdinalIgnoreCase))
{
ReadAndAssert(reader);
value = serializer.Deserialize<string>(reader);
}
else
{
reader.Skip();
}
ReadAndAssert(reader);
}
return new KeyValuePair<string, string>(key, value);
}
示例15: TryPopulateProperty
void TryPopulateProperty(DubProject prj, string propName, JsonReader j)
{
switch (propName.ToLowerInvariant())
{
case "displayname":
prj.Name = j.ReadAsString();
break;
case "name":
prj.packageName = j.ReadAsString();
break;
case "description":
prj.Description = j.ReadAsString();
break;
case "copyright":
prj.Copyright = j.ReadAsString();
break;
case "homepage":
prj.Homepage = j.ReadAsString();
break;
case "authors":
if (!j.Read() || j.TokenType != JsonToken.StartArray)
throw new JsonReaderException("Expected [ when parsing Authors");
prj.Authors.Clear();
while (j.Read() && j.TokenType != JsonToken.EndArray)
if (j.TokenType == JsonToken.String)
prj.Authors.Add(j.Value as string);
break;
case "dependencies":
if (!j.Read() || j.TokenType != JsonToken.StartObject)
throw new JsonReaderException("Expected { when parsing Authors");
DeserializeDubPrjDependencies(j, prj.CommonBuildSettings);
break;
case "configurations":
if (!j.Read() || j.TokenType != JsonToken.StartArray)
throw new JsonReaderException("Expected [ when parsing Configurations");
var sln = prj.ParentSolution;
if (sln != null && sln.Configurations.Count == 1 && sln.Configurations[0].Id == DubProjectConfiguration.DefaultConfigId)
sln.Configurations.Clear();
if (prj.Configurations.Count == 1 && prj.Configurations[0].Id == DubProjectConfiguration.DefaultConfigId)
prj.Configurations.Clear();
while (j.Read() && j.TokenType != JsonToken.EndArray)
prj.AddProjectAndSolutionConfiguration(DeserializeFromPackageJson(j));
break;
case "subpackages":
if (!j.Read() || j.TokenType != JsonToken.StartArray)
throw new JsonReaderException("Expected [ when parsing subpackages");
while (j.Read() && j.TokenType != JsonToken.EndArray)
ReadSubPackage(prj, j);
break;
case "buildtypes":
if (!j.Read() || j.TokenType != JsonToken.StartObject)
throw new JsonReaderException("Expected [ when parsing build types");
while (j.Read() && j.TokenType != JsonToken.EndObject)
{
var n = j.Value as string;
if (!prj.buildTypes.Contains(n))
prj.buildTypes.Add(n);
j.Skip();
}
prj.buildTypes.Sort();
break;
default:
TryDeserializeBuildSetting(prj.CommonBuildSettings, j);
break;
}
}