本文整理汇总了C#中Newtonsoft.Json.JsonWriter.WriteToken方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteToken方法的具体用法?C# JsonWriter.WriteToken怎么用?C# JsonWriter.WriteToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteToken方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var pair = (SwaggerOperationsExtended)value;
writer.WriteStartObject();
var count = pair.Keys.Count;
for (var i = 0; i < count; i++)
{
var key = pair.Keys.ElementAt(i);
var oVal = pair.Values.ElementAt(i);
writer.WritePropertyName(key.ToString().ToLower());
var tokenReader = new JTokenReader(JToken.FromObject(oVal));
writer.WriteToken(tokenReader);
}
writer.WriteEndObject();
}
示例2: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var d = value as LazyDocument;
if (d == null || d._Value == null)
return;
writer.WriteToken(d._Value.CreateReader());
}
示例3: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteToken(JsonToken.String, ((ThrowResult)value).ToString());
}
示例4: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value.GetType().BaseType == typeof(Array))
{
writer.WriteStartArray();
foreach (object o in (Array)value)
{
writer.WriteStartObject();
try
{
string[] fields = (string[])GetPropValue(o, "fields");
foreach (string field in fields)
{
var prop = GetPropValue(o, field);
if (prop != null)
{
writer.WritePropertyName(field);
try
{
writer.WriteValue(prop);
}
catch (Exception exp1)
{
writer.WriteValue(JsonConvert.SerializeObject(prop));
}
}
}
}
catch (Exception exp)
{
}
writer.WriteEndObject();
}
writer.WriteEndArray();
}
else
{
try
{
string[] fields = (string[])GetPropValue(value, "fields");
writer.WriteStartObject();
foreach (string field in fields)
{
var prop = GetPropValue(value, field);
if (prop != null)
{
writer.WritePropertyName(field);
try
{
writer.WriteValue(prop);
}
catch (Exception exp1)
{
writer.WriteValue(JsonConvert.SerializeObject(prop));
}
}
}
writer.WriteEndObject();
}
catch (Exception exp)
{
JToken j = JToken.FromObject(value);
writer.WriteToken(j.CreateReader());
}
}
}
示例5: WriteJson
/// <summary>Writes the JSON representation of the object.</summary>
/// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
/// <param name="value">The value.</param>
/// <param name="serializer">The calling serializer.</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var contract = serializer.ContractResolver.ResolveContract(value.GetType());
contract.Converter = null;
var jObject = JObject.FromObject(value, serializer);
jObject.AddFirst(new JProperty(_discriminator, value.GetType().Name));
writer.WriteToken(jObject.CreateReader());
contract.Converter = this;
}
示例6: WriteJson
public override void WriteJson(JsonWriter w, object o, JsonSerializer s)
{
var result = "";
if (o is byte[])
{
result += "data:application/octet-stream;base64,";
result += Convert.ToBase64String((byte[])o);
}
else if (o is string)
{
result += "data:text/plain;base64,";
result += Convert.ToBase64String(Encoding.UTF8.GetBytes((string)o));
}
else if (o is Bitmap)
{
result += "data:image/png;base64,";
var bmp = (Bitmap) o;
var stream = new MemoryStream();
bmp.Save(stream, ImageFormat.Png);
result += Convert.ToBase64String(stream.GetBuffer());
}
else
{
throw new NotImplementedException();
}
w.WriteToken(JsonToken.String, result);
}
示例7: WriteJson
/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
/// <param name="value">The value.</param>
/// <param name="serializer">The calling serializer.</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var v8Item = value as V8ScriptItem;
var jsType = v8Item.GetJsType();
object outObj;
if (jsType == JsTypes.jsError)
{
Dictionary<string, object> obj = new Dictionary<string, object>();
obj["message"] = v8Item.GetProperty("message") as string;
obj["stack"] = v8Item.GetProperty("stack") as string;
foreach (var pname in v8Item.GetPropertyNames())
{
var item = v8Item.GetProperty(pname);
if (ShouleSerialize(item, out outObj))
{
obj[pname] = outObj;
}
}
serializer.Serialize(writer, obj, obj.GetType());
}
else if (jsType == JsTypes.JsObject || jsType == JsTypes.JsArray || jsType == JsTypes.jsArguments)
{
try
{
var json = v8Item.Engine.Script.JSON.stringify(v8Item);
if (writer is JTokenWriter)
{
var tw = new StringReader(json);
var jsonReader = new JsonTextReader(tw);
writer.WriteToken(jsonReader);
}
else
{
writer.WriteRaw(json);
}
}
catch (Exception)
{
throw;
}
}
else if (jsType == JsTypes.JsDate)
{
var dateString = (string)v8Item.InvokeMethod("toISOString", new object[0]);
DateTime dt = DateTime.Parse(dateString, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.RoundtripKind);
serializer.Serialize(writer, dt, dt.GetType());
}
else
{
writer.WriteNull();
}
}