本文整理汇总了C#中Newtonsoft.Json.JsonWriter.WriteRaw方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteRaw方法的具体用法?C# JsonWriter.WriteRaw怎么用?C# JsonWriter.WriteRaw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteRaw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
ElasticQuery term = (ElasticQuery)value;
if (term != null)
{
writer.WriteStartObject();
writer.WriteRaw("\"from\": " + term.From);
writer.WriteRaw(",\"size\": " + term.Size + ",");
writer.WritePropertyName("query");
serializer.Serialize(writer, term.Query);
if (term.Fields != null && term.Fields.Count > 0)
{
writer.WritePropertyName("fields");
writer.WriteStartArray();
foreach (var field in term.Fields)
{
writer.WriteRawValue("\"" + field + "\"");
}
writer.WriteEndArray();
}
if (term.SortItems != null && term.SortItems.Count > 0)
{
writer.WritePropertyName("sort");
writer.WriteStartObject();
foreach (var sortItem in term.SortItems)
{
if (sortItem != null)
{
writer.WritePropertyName(sortItem.FieldName);
writer.WriteValue(sortItem.SortType.ToString().ToLower());
}
}
writer.WriteEndObject();
}
//facets
if (term.Facets != null)
{
writer.WritePropertyName("facets");
serializer.Serialize(writer, term.Facets);
}
//hightlight
if(term.Hightlight!=null)
{
writer.WritePropertyName("highlight");
serializer.Serialize(writer,term.Hightlight);
}
if (term.Explain)
{
writer.WriteRaw(",\"explain\": " + term.Explain.ToString().ToLower());
}
writer.WriteEndObject();
}
}
示例2: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var filterList = value as FilterList;
if (filterList == null) throw new InvalidOperationException("FilterListConverter attribute is not applied to FilterList class");
if(filterList.Data.Count == 1)
{
writer.WriteRaw(JsonConvert.SerializeObject(filterList.Data[0]));
}
else
{
writer.WriteRaw(JsonConvert.SerializeObject(new FilterGroup(filterList.Data)));
}
}
示例3: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var filter = value as Filter;
if(filter == null) throw new InvalidOperationException("FilterConverter attribute is not applied to Filter class");
if(filter.Value is bool) //lowercase boolean values
{
writer.WriteRaw(filter.Value.ToString().ToLower());
}
else
{
writer.WriteRaw(filter.Value.ToString());
}
}
示例4: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var request = value as IMultiPercolateRequest;
if (request == null) return;
if (request.Percolations == null) return;
var settings = serializer.GetConnectionSettings();
var elasticsearchSerializer = settings.Serializer;
if (elasticsearchSerializer == null) return;
foreach (var percolation in request.Percolations)
{
var requestParameters = percolation.GetRequestParameters() ?? new PercolateRequestParameters();
var header = new PercolateHeader
{
percolate_index = requestParameters.GetQueryStringValue<string>("percolate_index"),
percolate_type = requestParameters.GetQueryStringValue<string>("percolate_type"),
routing = requestParameters.GetQueryStringValue<string[]>("routing"),
preference = requestParameters.GetQueryStringValue<string>("preference"),
percolate_routing = requestParameters.GetQueryStringValue<string>("percolate_routing"),
percolate_preference = requestParameters.GetQueryStringValue<string>("percolate_preference"),
version = requestParameters.GetQueryStringValue<long?>("version")
};
var routeValues = (percolation as IRequest)?.RouteValues;
if (routeValues != null)
{
header.id = routeValues.Get<Id>("id");
header.index = routeValues.Get<IndexName>("index");
header.type = routeValues.Get<TypeName>("type");
if (request.Index != null && request.Index.EqualsMarker(header.index)) header.index = null;
if (request.Type != null && request.Type.EqualsMarker(header.type)) header.type = null;
}
var headerBytes = elasticsearchSerializer.SerializeToBytes(header, SerializationFormatting.None);
writer.WriteRaw($"{{\"{percolation.MultiPercolateName}\":" + headerBytes.Utf8String() + "}\n");
if (percolation == null)
{
writer.WriteRaw("{}\n");
}
else
{
var bodyBytes = elasticsearchSerializer.SerializeToBytes(percolation, SerializationFormatting.None);
writer.WriteRaw(bodyBytes.Utf8String() + "\n");
}
}
}
示例5: Serialize
/// <exception cref="ArgumentNullException">when <paramref name="writer"/> is null</exception>
/// <exception cref="ArgumentNullException">when <paramref name="value"/> is null</exception>
public new void Serialize(JsonWriter writer, object value)
{
if (writer == null) throw new ArgumentNullException("writer");
if (value == null) throw new ArgumentNullException("value");
if( ReflectionUtilities.Implements(value.GetType(), typeof(ISerializableToJavaScript)) && !customSerializationObjects.Contains(value) )
{
customSerializationObjects.Add(value);
((ISerializableToJavaScript) value).SerializeToJavaScript(this, writer);
customSerializationObjects.Remove(value);
return;
}
var attribute = ReflectionUtilities.GetAttribute<JavaScriptObjectAttribute>(value);
if( attribute != null && !string.IsNullOrEmpty(attribute.Prefix) ) writer.WriteRaw(attribute.Prefix);
base.Serialize(writer, value);
if( attribute != null && !string.IsNullOrEmpty(attribute.Suffix) ) writer.WriteRaw(attribute.Suffix);
}
示例6: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var request = value as IMultiSearchRequest;
if (request == null) return;
var settings = serializer.GetConnectionSettings();
var elasticsearchSerializer = settings.Serializer;
if (elasticsearchSerializer == null) return;
if (request.Operations == null) return;
foreach (var operation in request.Operations.Values)
{
var indices = (request.Index != null && !request.Index.Equals(operation.Index))
? operation.Index
: null;
var types = (request.Type != null && !request.Type.Equals(operation.Type))
? operation.Type
: null;
var searchType = operation.RequestParameters.GetQueryStringValue<SearchType>("search_type").GetStringValue();
if (searchType == "query_then_fetch")
searchType = null;
var header = new
{
index = (indices as IUrlParameter)?.GetString(settings),
type = (types as IUrlParameter)?.GetString(settings),
search_type = searchType,
preference = operation.Preference,
routing = operation.Routing,
ignore_unavailable = operation.IgnoreUnavalable
};
var headerBytes = elasticsearchSerializer.SerializeToBytes(header, SerializationFormatting.None);
writer.WriteRaw(headerBytes.Utf8String() + "\n");
var bodyBytes = elasticsearchSerializer.SerializeToBytes(operation, SerializationFormatting.None);
writer.WriteRaw(bodyBytes.Utf8String() + "\n");
}
}
示例7: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var request = (IMultiSearchTemplateRequest)value;
if (request == null) return;
var settings = serializer.GetConnectionSettings();
var elasticsearchSerializer = settings.Serializer;
if (elasticsearchSerializer == null) return;
if (request.Operations == null) return;
foreach (var operation in request.Operations.Values)
{
IUrlParameter indices = request.Index == null || !request.Index.Equals(operation.Index)
? operation.Index
: null;
IUrlParameter types = request.Type == null || !request.Type.Equals(operation.Type)
? operation.Type
: null;
var searchType = operation.RequestParameters.GetQueryStringValue<SearchType>("search_type").GetStringValue();
if (searchType == "query_then_fetch")
searchType = null;
var header = new
{
index = indices?.GetString(settings),
type = types?.GetString(settings),
search_type = searchType,
preference = operation.Preference,
routing = operation.Routing,
ignore_unavailable = operation.IgnoreUnavalable
};
var headerString = elasticsearchSerializer.SerializeToString(header, SerializationFormatting.None);
writer.WriteRaw($"{headerString}\n");
var bodyString = elasticsearchSerializer.SerializeToString(operation, SerializationFormatting.None);
writer.WriteRaw($"{bodyString}\n");
};
}
示例8: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var tsr = value as TimeseriesResult;
if(tsr == null)
throw new InvalidOperationException("Cannot serialize type {0}".FormatString(value.GetType()));
writer.WriteRaw(JsonConvert.SerializeObject(new {
RollupType = tsr.RollupType.ToString(),
Timeseries = tsr.Timeseries.Values,
Labels = from k in tsr.Timeseries.Keys select new {label = k},
TimeseriesInfo = tsr.Timeseries.Values.Select(ts => ts.Select(t => t.Value))
}, new JsonConverter[] { new TimeseriesConverter(), new TimeseriesPeriodConverter() }));
}
示例9: WriteJson
// Custom Biggylist serialization which simply writes each object, separated by newlines, to the output
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var list = value as IEnumerable;
// Loop over all items in the list
foreach (var item in list)
{
// Serialize the object to the writer
serializer.Serialize(writer, item);
// Separate with newline characters
writer.WriteRaw("\r\n");
}
}
示例10: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var bulk = value as IBulkRequest;
var settings = serializer?.GetConnectionSettings();
var elasticsearchSerializer = settings?.Serializer;
if (elasticsearchSerializer == null|| bulk?.Operations == null) return ;
foreach(var op in bulk.Operations)
{
op.Index = op.Index ?? bulk.Index ?? op.ClrType;
if (op.Index.EqualsMarker(bulk.Index)) op.Index = null;
op.Type = op.Type ?? bulk.Type ?? op.ClrType;
if (op.Type.EqualsMarker(bulk.Type)) op.Type = null;
op.Id = op.GetIdForOperation(settings.Inferrer);
var opJson = elasticsearchSerializer.SerializeToString(op, SerializationFormatting.None);
writer.WriteRaw($"{{\"{op.Operation}\":" + opJson + "}\n");
var body = op.GetBody();
if (body == null) continue;
var bodyJson = elasticsearchSerializer.SerializeToString(body, SerializationFormatting.None);
writer.WriteRaw(bodyJson + "\n");
}
}
示例11: WriteJson
/// <summary>
/// Data should be written as an array of arrays, according to Flot specification.
/// </summary>
/// <param name="writer"></param>
/// <param name="value">Should be a dictionary.</param>
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
// I'm not sure if this is needed.
if (!(value is IDictionary)) throw new Exception("Value is not a dictionary.");
foreach (dynamic teste in (IEnumerable)value)
{
writer.WriteStartArray();
serializer.Serialize(writer, teste.Key);
serializer.Serialize(writer, teste.Value);
writer.WriteEndArray();
writer.WriteRaw(", ");
}
}
示例12: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
HasChildFilter term = (HasChildFilter)value;
if (term != null)
{
writer.WriteStartObject();
writer.WritePropertyName("has_child");
writer.WriteStartObject();
if (term.Query != null)
{
writer.WritePropertyName("query");
serializer.Serialize(writer, term.Query);
writer.WriteRaw(",\"type\": \"" + term.Type+"\"");
if(term.Scope!=null)
{
writer.WriteRaw(",\"_scope\": \"" + term.Scope + "\"");
}
}
writer.WriteEndObject();
writer.WriteEndObject();
}
}
示例13: WriteJson
public override void WriteJson(JsonWriter writer, object value)
{
if (value is DateTime)
{
writer.WriteValue(JsonConvert.ConvertDateTimeToJavaScriptTicks((DateTime)value));
}
else if (value is DateTime? && ((DateTime?)value).HasValue)
{
writer.WriteValue(JsonConvert.ConvertDateTimeToJavaScriptTicks(((DateTime?)value).Value));
}
else
{
writer.WriteRaw("null");
}
}
示例14: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value == null)
{
if (serializer.NullValueHandling == NullValueHandling.Include)
{
writer.WriteNull();
}
return;
}
writer.WriteStartArray();
byte[] arbitraryData = (byte[]) value;
writer.WriteRaw(string.Join(",", arbitraryData));
writer.WriteEndArray();
}
示例15: WriteTo
/// <summary>
/// Writes this token to a <see cref="JsonWriter"/>.
/// </summary>
/// <param name="writer">A <see cref="JsonWriter"/> into which this method will write.</param>
/// <param name="converters">A collection of <see cref="JsonConverter"/> which will be used when writing the token.</param>
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters) {
writer.WriteStartObject();
if (this.WithComment) {
var lPath = writer.Path;
var lState = writer.WriteState;
StringBuilder lComments = new StringBuilder();
int lLevel = (lPath.Split('.').Length + 1) * 2;
if (lPath == "") lLevel = 2;
writer.WriteWhitespace("\r\n");
for (int lCount = 0; lCount < mComment.Count; lCount++) {
if (lLevel > 0) writer.WriteWhitespace(new string(' ', lLevel));
writer.WriteRaw("//" + mComment[lCount]);
if (lCount + 1 < mComment.Count) writer.WriteWhitespace("\r\n");
}
}
var _properties = base.Properties();
foreach (var lProperty in _properties) {
lProperty.WriteTo(writer, converters);
}
writer.WriteEndObject();
//base.WriteTo(writer, converters);
}