当前位置: 首页>>代码示例>>C#>>正文


C# JsonWriter.WriteRawValue方法代码示例

本文整理汇总了C#中JsonWriter.WriteRawValue方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteRawValue方法的具体用法?C# JsonWriter.WriteRawValue怎么用?C# JsonWriter.WriteRawValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonWriter的用法示例。


在下文中一共展示了JsonWriter.WriteRawValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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)
 {
     switch (_valueType)
       {
     case JsonTokenType.Comment:
       writer.WriteComment(_value.ToString());
       break;
     case JsonTokenType.Integer:
       WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToInt64(v, CultureInfo.InvariantCulture)), _value);
       break;
     case JsonTokenType.Float:
       WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToDouble(v, CultureInfo.InvariantCulture)), _value);
       break;
     case JsonTokenType.String:
       WriteConvertableValue(writer, converters, v => writer.WriteValue(v.ToString()), _value);
       break;
     case JsonTokenType.Boolean:
       WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToBoolean(v, CultureInfo.InvariantCulture)), _value);
       break;
     case JsonTokenType.Date:
       WriteConvertableValue(writer, converters, v =>
       {
     if (v is DateTimeOffset)
       writer.WriteValue((DateTimeOffset)v);
     else
       writer.WriteValue(Convert.ToDateTime(v, CultureInfo.InvariantCulture));
       }, _value);
       break;
     case JsonTokenType.Raw:
       writer.WriteRawValue(_value.ToString());
       break;
     case JsonTokenType.Null:
       writer.WriteNull();
       break;
     case JsonTokenType.Undefined:
       writer.WriteUndefined();
       break;
     default:
       throw MiscellaneousUtils.CreateArgumentOutOfRangeException("TokenType", _valueType, "Unexpected token type.");
       }
 }
开发者ID:jabbo,项目名称:Jabbo,代码行数:46,代码来源:JValue.cs

示例2: SerializeValue

    private void SerializeValue(JsonWriter writer, object value, JsonConverter memberConverter)
    {
      JsonConverter converter = memberConverter;

      if (value == null)
      {
        writer.WriteNull();
      }
      else if (converter != null
        || _serializer.HasClassConverter(value.GetType(), out converter)
        || _serializer.HasMatchingConverter(value.GetType(), out converter))
      {
        SerializeConvertable(writer, converter, value);
      }
      else if (JsonConvert.IsJsonPrimitive(value))
      {
        writer.WriteValue(value);
      }
      else if (value is JToken)
      {
        ((JToken)value).WriteTo(writer, (_serializer.Converters != null) ? _serializer.Converters.ToArray() : null);
      }
      else if (value is JsonRaw)
      {
        writer.WriteRawValue(((JsonRaw)value).Content);
      }
      else
      {
        JsonContract contract = _serializer.ContractResolver.ResolveContract(value.GetType());

        if (contract is JsonObjectContract)
        {
          SerializeObject(writer, value, (JsonObjectContract)contract);
        }
        else if (contract is JsonDictionaryContract)
        {
          SerializeDictionary(writer, (IDictionary)value, (JsonDictionaryContract)contract);
        }
        else if (contract is JsonArrayContract)
        {
          if (value is IList)
          {
            SerializeList(writer, (IList)value, (JsonArrayContract)contract);
          }
          else if (value is IEnumerable)
          {
            SerializeEnumerable(writer, (IEnumerable)value, (JsonArrayContract)contract);
          }
          else
          {
            throw new Exception("Cannot serialize '{0}' into a JSON array. Type does not implement IEnumerable.".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
          }
        }
      }
    }
开发者ID:oduma,项目名称:Sciendo.Fitas.Droid,代码行数:55,代码来源:JsonSerializerWriter.cs

示例3: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     string s = Enum.GetName(value.GetType(), value);
     //writer.WriteValue(s.LowerCaseFirst());
     writer.WriteRawValue(s.LowerCaseFirst());
 }
开发者ID:JulsMan,项目名称:googlevisualizationsdotnet,代码行数:6,代码来源:CustomConverters.cs

示例4: foreach

        void IJsonSerializable.Serialize(JsonWriter writer)
        {
            // Types
            if (Types != null && Types.Any())
            {
                writer.WritePropertyName("types");
                writer.WriteStartObject();
                foreach (var type in Types)
                {
                    writer.WritePropertyName(type);
                    writer.WriteRawValue(GetTypeJson(type));
                }
                writer.WriteEndObject();
            }

            if (Instances != null && Instances.Any())
            {
                writer.WritePropertyName("instances");
                writer.WriteStartObject();

                foreach (var typeItem in Instances)
                {
                    writer.WritePropertyName(typeItem.Key);
                    writer.WriteStartObject();

                    // Serialize static property values
                    if (typeItem.Value.StaticProperties.Count > 0)
                    {
                        writer.WritePropertyName("static");
                        writer.Serialize(
                            typeItem.Value.StaticProperties.ToDictionary(
                            property => property.Name,
                            property => JsonConverter.GetPropertyValue(property, property.DeclaringType)));
                    }

                    // Serialize instances
                    foreach (var instanceItem in typeItem.Value.Instances)
                    {
                        writer.WritePropertyName(instanceItem.Key);
                        writer.Serialize(instanceItem.Value);
                    }

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            if (Conditions != null && Conditions.Any())
            {
                writer.WritePropertyName("conditions");
                writer.Serialize(Conditions);
            }

            if (Events != null && Events.Any())
            {
                writer.WritePropertyName("events");
                writer.Serialize(Events);
            }

            if (Model != null && Model.Any())
            {
                writer.WritePropertyName("model");
                writer.Serialize(Model);
            }

            if (ServerInfo != null)
            {
                writer.WritePropertyName("serverInfo");
                writer.Serialize(ServerInfo);
            }

            if (Changes != null && Changes.Any())
            {
                writer.WritePropertyName("changes");
                writer.Serialize(Changes.Where(modelEvent => !(modelEvent is ModelValueChangeEvent) || ExoWeb.IncludeInClientModel(((ModelValueChangeEvent)modelEvent).Property)));
            }
        }
开发者ID:vc3,项目名称:ExoWeb,代码行数:78,代码来源:ServiceResponse.cs

示例5: SerializeValue

    private void SerializeValue(JsonWriter writer, object value, JsonConverter memberConverter)
    {
      JsonConverter converter;

      if (value == null)
      {
        writer.WriteNull();
      }
      else if (memberConverter != null)
      {
        memberConverter.WriteJson(writer, value);
      }
      else if (HasClassConverter(value.GetType(), out converter))
      {
        converter.WriteJson(writer, value);
      }
      else if (HasMatchingConverter(value.GetType(), out converter))
      {
        converter.WriteJson(writer, value);
      }
      else if (JavaScriptConvert.IsJsonPrimitive(value))
      {
        writer.WriteValue(value);
      }
      else if (value is IList)
      {
        SerializeList(writer, (IList)value);
      }
      else if (value is IDictionary)
      {
        SerializeDictionary(writer, (IDictionary)value);
      }
      else if (value is ICollection)
      {
        SerializeCollection(writer, (ICollection)value);
      }
      else if (value is IEnumerable)
      {
        SerializeEnumerable(writer, (IEnumerable)value);
      }
      else if (value is JsonRaw)
      {
        writer.WriteRawValue(((JsonRaw)value).Content);
      }
      else
      {
        SerializeObject(writer, value);
      }
    }
开发者ID:kisflying,项目名称:kion,代码行数:49,代码来源:JsonSerializer.cs


注:本文中的JsonWriter.WriteRawValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。