本文整理汇总了C#中Jayrock.Json.JsonWriter类的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter类的具体用法?C# JsonWriter怎么用?C# JsonWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonWriter类属于Jayrock.Json命名空间,在下文中一共展示了JsonWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Format
public virtual void Format(object o, JsonWriter writer)
{
if (writer == null)
throw new ArgumentNullException("writer");
if (JNull.LogicallyEquals(o))
{
FormatNull(o, writer);
return;
}
//
// Handle primitive mapping specially.
//
switch (Type.GetTypeCode(o.GetType()))
{
case TypeCode.Byte : FormatByte((byte) o, writer); return;
case TypeCode.Int16 : FormatInt16((short) o, writer); return;
case TypeCode.Int32 : FormatInt32((int) o, writer); return;
case TypeCode.Int64 : FormatInt64((long) o, writer); return;
case TypeCode.Decimal : FormatDecimal((decimal) o, writer); return;
case TypeCode.Single : FormatSingle((float) o, writer); return;
case TypeCode.Double : FormatDouble((double) o, writer); return;
case TypeCode.Boolean : FormatBoolean((bool) o, writer); return;
case TypeCode.String : FormatString((string) o, writer); return;
}
//
// For all other types, go through a method that can be
// overridden by subtypes.
//
FormatOther(o, writer);
}
示例2: Playback
public void Playback(JsonWriter writer)
{
if (writer == null)
throw new ArgumentNullException("writer");
writer.WriteFromReader(CreatePlayer());
}
示例3: WritePhoneNumber
private static void WritePhoneNumber(JsonWriter writer, string location, string number)
{
writer.WriteStartObject(); // {
writer.WriteMember("Location"); // "Location" :
writer.WriteString(location); // "...",
writer.WriteMember("Number"); // "Number" :
writer.WriteString(number); // "..."
writer.WriteEndObject(); // }
}
示例4: ArgumentNullException
void IJsonExportable.Export(ExportContext context, JsonWriter writer)
{
if (context == null)
throw new ArgumentNullException("context");
if (writer == null)
throw new ArgumentNullException("writer");
writer.WriteNull();
}
示例5: FormatOther
protected virtual void FormatOther(object o, JsonWriter writer)
{
//
// If the value is is JSON-aware then let it do the job.
//
IJsonFormattable jsonFormattable = o as IJsonFormattable;
if (jsonFormattable != null)
{
FormatFormattable(jsonFormattable, writer);
return;
}
//
// If the value is a dictionary then encode it as a JSON
// object.
//
IDictionary dictionary = o as IDictionary;
if (dictionary != null)
{
FormatDictionary(dictionary, writer);
return;
}
//
// If the value is enumerable then encode it as a JSON
// array.
//
IEnumerable enumerable = o as IEnumerable;
if (enumerable != null)
{
FormatEnumerable(enumerable, writer);
return;
}
//
// For all other types, write out its string representation as a
// simple JSON string.
//
writer.WriteString(Convert.ToString(o, CultureInfo.InvariantCulture));
}
示例6: Process
public virtual void Process(JsonReader request, JsonWriter response)
{
if (request == null)
throw new ArgumentNullException("request");
if (response == null)
throw new ArgumentNullException("response");
IDictionary requestObject;
try
{
requestObject = ParseRequest(request);
}
catch (BadRequestException e)
{
requestObject = e.Request as IDictionary;
WriteResponse(
CreateResponse(requestObject, /* result */ null,
OnError(e.InnerException, requestObject)),
response);
return;
}
IDictionary responseObject = Invoke(requestObject);
WriteResponse(responseObject, response);
}
示例7: Export
public void Export(ExportContext context, JsonWriter writer, object source)
{
if (context == null) throw new ArgumentNullException("context");
if (writer == null) throw new ArgumentNullException("writer");
if (source == null) throw new ArgumentNullException("source");
object value = _property.GetValue(source);
if (JsonNull.LogicallyEquals(value) || value.Equals(_defaultValue))
return;
writer.WriteMember(_property.Name);
context.Export(value, writer);
}
示例8: Export
public override void Export(object value, JsonWriter writer)
{
ExportCalled = true;
base.Export(value, writer);
}
示例9: Export
protected virtual void Export(ExportContext context, JsonWriter writer)
{
if (context == null)
throw new ArgumentNullException("context");
if (writer == null)
throw new ArgumentNullException("writer");
writer.WriteStartObject();
foreach (string name in NameIndexList)
{
writer.WriteMember(name);
context.Export(InnerHashtable[name], writer);
}
writer.WriteEndObject();
}
示例10: FormatDouble
protected virtual void FormatDouble(double value, JsonWriter writer)
{
writer.WriteNumber(value.ToString(CultureInfo.InvariantCulture));
}
示例11: Export
public void Export(JsonWriter writer)
{
if (writer == null)
throw new ArgumentNullException("writer");
writer.WriteStartObject();
foreach (string name in NameIndexList)
{
writer.WriteMember(name);
writer.WriteValue(InnerHashtable[name]);
}
writer.WriteEndObject();
}
示例12: WriteRssToJson
private static void WriteRssToJson(Channel channel, JsonWriter writer)
{
writer.WriteStartObject();
writer.WriteMember("title");
writer.WriteString(channel.title);
writer.WriteMember("link");
writer.WriteString(channel.link);
writer.WriteMember("items");
writer.WriteStartArray();
foreach (Item item in channel.item)
WriteRssToJson(item, writer);
writer.WriteEndArray();
writer.WriteEndObject();
}
示例13: FormatEnumerable
protected virtual void FormatEnumerable(IEnumerable enumerable, JsonWriter writer)
{
writer.WriteArray(enumerable);
}
示例14: Export
protected virtual void Export(ExportContext context, JsonWriter writer)
{
if (context == null)
throw new ArgumentNullException("context");
if (writer == null)
throw new ArgumentNullException("writer");
writer.WriteStartArray();
foreach (object value in this)
context.Export(value, writer);
writer.WriteEndArray();
}
示例15: Export
public void Export(object value, JsonWriter writer)
{
ExportCalled = true;
JsonConvert.Export(value, writer);
}