本文整理汇总了C#中Newtonsoft.Json.JsonTextReader.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextReader.Skip方法的具体用法?C# JsonTextReader.Skip怎么用?C# JsonTextReader.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextReader
的用法示例。
在下文中一共展示了JsonTextReader.Skip方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadJsonEncodedParameters
public virtual NameValueCollection ReadJsonEncodedParameters(System.IO.Stream incomingStream)
{
if (incomingStream == null)
{
throw new ArgumentNullException("incomingStream");
}
NameValueCollection parameters = new NameValueCollection();
var jsonReader = new JsonTextReader(new StreamReader(incomingStream));
while (jsonReader.Read())
{
// Not interested in nested objects/arrays!
if (jsonReader.Depth > 1)
{
jsonReader.Skip();
}
else if (jsonReader.TokenType == JsonToken.PropertyName)
{
string key = jsonReader.Value.ToString();
if (jsonReader.Read())
{
switch (jsonReader.TokenType)
{
case JsonToken.Boolean:
case JsonToken.Date:
case JsonToken.Float:
case JsonToken.Integer:
case JsonToken.Null:
case JsonToken.String:
parameters[key] = jsonReader.Value.ToString();
break;
}
}
}
}
return parameters;
}
示例2: DeserializeRequest
public void DeserializeRequest(Message message, object[] parameters)
{
object bodyFormatProperty;
if (!message.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out bodyFormatProperty) ||
(bodyFormatProperty as WebBodyFormatMessageProperty).Format != WebContentFormat.Raw)
{
throw new InvalidOperationException("Incoming messages must have a body format of Raw. Is a ContentTypeMapper set on the WebHttpBinding?");
}
XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents();
bodyReader.ReadStartElement("Binary");
byte[] rawBody = bodyReader.ReadContentAsBase64();
MemoryStream ms = new MemoryStream(rawBody);
StreamReader sr = new StreamReader(ms);
JsonSerializer serializer = new JsonSerializer
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects
};
if (parameters.Length == 1)
{
// single parameter, assuming bare
parameters[0] = serializer.Deserialize(sr, this.operation.Messages[0].Body.Parts[0].Type);
}
else
{
// multiple parameter, needs to be wrapped
JsonReader reader = new JsonTextReader(sr);
reader.Read();
if (reader.TokenType != JsonToken.StartObject)
{
throw new InvalidOperationException("Input needs to be wrapped in an object");
}
reader.Read();
while (reader.TokenType == JsonToken.PropertyName)
{
string parameterName = reader.Value as string;
reader.Read();
if (this.parameterNames.ContainsKey(parameterName))
{
int parameterIndex = this.parameterNames[parameterName];
parameters[parameterIndex] = serializer.Deserialize(reader, this.operation.Messages[0].Body.Parts[parameterIndex].Type);
}
else
{
reader.Skip();
}
reader.Read();
}
reader.Close();
}
sr.Close();
ms.Close();
}
示例3: ParseJsonResponse
public static ApiResponse ParseJsonResponse(Stream stream)
{
using (var jsonReader = new JsonTextReader(new StreamReader(stream)))
{
var apiResponse = new ApiResponse();
while (jsonReader.Read())
{
if (jsonReader.TokenType == JsonToken.PropertyName)
{
switch ((string)jsonReader.Value)
{
case "statusCode":
apiResponse.StatusCode = jsonReader.ReadAsInt32() ?? 0;
break;
case "count":
apiResponse.Count = jsonReader.ReadAsInt32() ?? 0;
break;
case "response":
apiResponse.Response = jsonReader.GetInnerJson();
break;
case "error":
jsonReader.Read();
throw ParseError(jsonReader);
default:
jsonReader.Skip();
break;
}
}
}
return apiResponse;
}
}
示例4: Extract
/// <summary/>
public override IEnumerable<IRow> Extract(IUnstructuredReader input, IUpdatableRow output)
{
if (input.Length == 0)
yield break;
using (var reader = new JsonTextReader(new StreamReader(input.BaseStream)))
{
IColumn currentColumn = null;
StringBuilder valueBuilder = null;
JsonTextWriter writer = null;
var startedGlobalObjects = 0;
var startedLocalObjects = 0;
var startedGlobalArrays = 0;
var startedLocalArrays = 0;
while (reader.Read())
{
switch (reader.TokenType)
{
case JsonToken.StartArray:
startedGlobalArrays++;
if (currentColumn != null && currentColumn.Type == typeof(string))
{
if (writer == null)
{
valueBuilder = new StringBuilder();
writer = new JsonTextWriter(new StringWriter(valueBuilder));
}
startedLocalArrays++;
writer.WriteStartArray();
}
break;
case JsonToken.EndArray:
startedGlobalArrays--;
if (writer != null)
{
startedLocalArrays--;
writer.WriteEndArray();
}
if (currentColumn != null && valueBuilder != null
&& startedLocalArrays == 0 && startedLocalObjects == 0)
{
output.Set(currentColumn.Name, valueBuilder.ToString());
writer = null;
valueBuilder = null;
currentColumn = null;
}
if (startedGlobalArrays == 0)
{
yield break;
}
break;
case JsonToken.StartObject:
startedGlobalObjects++;
if (currentColumn != null && currentColumn.Type == typeof(string))
{
if (writer == null)
{
valueBuilder = new StringBuilder();
writer = new JsonTextWriter(new StringWriter(valueBuilder));
}
startedLocalObjects++;
writer.WriteStartObject();
}
break;
case JsonToken.EndObject:
startedGlobalObjects--;
if (writer != null)
{
startedLocalObjects--;
writer.WriteEndObject();
}
if (currentColumn != null && valueBuilder != null
&& startedLocalArrays == 0 && startedLocalObjects == 0)
{
output.Set(currentColumn.Name, valueBuilder.ToString());
writer = null;
valueBuilder = null;
currentColumn = null;
}
if (startedGlobalObjects == 0)
yield return output.AsReadOnly();
break;
case JsonToken.PropertyName:
if (writer != null)
{
writer.WritePropertyName(reader.Value.ToString());
}
else
{
var currentPropertyName = reader.Value.ToString();
currentColumn = output.Schema
.FirstOrDefault(s => s.Name == currentPropertyName);
if (currentColumn == null)
reader.Skip();
}
break;
//.........这里部分代码省略.........