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


C# JsonWriter.WriteEndArray方法代码示例

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


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

示例1: ValueFormatting

    public void ValueFormatting()
    {
      StringBuilder sb = new StringBuilder();
      StringWriter sw = new StringWriter(sb);

      using (JsonWriter jsonWriter = new JsonWriter(sw))
      {
        jsonWriter.WriteStartArray();
        jsonWriter.WriteValue('@');
        jsonWriter.WriteValue("\r\n\t\f\b?{\\r\\n\"\'");
        jsonWriter.WriteValue(true);
        jsonWriter.WriteValue(10);
        jsonWriter.WriteValue(10.99);
        jsonWriter.WriteValue(0.99);
        jsonWriter.WriteValue(0.000000000000000001d);
        jsonWriter.WriteValue(0.000000000000000001m);
        jsonWriter.WriteValue(null);
        jsonWriter.WriteValue("This is a string.");
        jsonWriter.WriteNull();
        jsonWriter.WriteUndefined();
        jsonWriter.WriteEndArray();
      }

      const string expected = @"[""@"",""\r\n\t\f\b?{\\r\\n\""'"",true,10,10.99,0.99,1E-18,0.000000000000000001,,""This is a string."",null,undefined]";
      string result = sb.ToString();

      Console.WriteLine("ValueFormatting");
      Console.WriteLine(result);

      Assert.AreEqual(expected, result);
    }
开发者ID:webgrid,项目名称:WebGrid,代码行数:31,代码来源:JsonWriterTest.cs

示例2: 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)
        {
            DataTable table = (DataTable)value;
            DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;

            writer.WriteStartArray();

            foreach (DataRow row in table.Rows)
            {
                writer.WriteStartObject();
                foreach (DataColumn column in row.Table.Columns)
                {
                    object columnValue = row[column];

                    if (serializer.NullValueHandling == NullValueHandling.Ignore && (columnValue == null || columnValue == DBNull.Value))
                    {
                        continue;
                    }

                    writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(column.ColumnName) : column.ColumnName);
                    serializer.Serialize(writer, columnValue);
                }
                writer.WriteEndObject();
            }

            writer.WriteEndArray();
        }
开发者ID:rlugojr,项目名称:Newtonsoft.Json,代码行数:33,代码来源:DataTableConverter.cs

示例3: WriteJsonValue

 private void WriteJsonValue(JsonWriter writer, IJsonValue value)
 {
     switch (value.ValueType)
     {
         case JsonValueType.Array:
         {
             JsonArray a = value.GetArray();
             writer.WriteStartArray();
             for (int i = 0; i < a.Count; i++)
             {
                 WriteJsonValue(writer, a[i]);
             }
             writer.WriteEndArray();
         }
             break;
         case JsonValueType.Boolean:
         {
             writer.WriteValue(value.GetBoolean());
         }
             break;
         case JsonValueType.Null:
         {
             writer.WriteNull();
         }
             break;
         case JsonValueType.Number:
         {
             // JsonValue doesn't support integers
             // serialize whole numbers without a decimal point
             double d = value.GetNumber();
             bool isInteger = (d % 1 == 0);
             if (isInteger && d <= long.MaxValue && d >= long.MinValue)
                 writer.WriteValue(Convert.ToInt64(d));
             else
                 writer.WriteValue(d);
         }
             break;
         case JsonValueType.Object:
         {
             JsonObject o = value.GetObject();
             writer.WriteStartObject();
             foreach (KeyValuePair<string, IJsonValue> v in o)
             {
                 writer.WritePropertyName(v.Key);
                 WriteJsonValue(writer, v.Value);
             }
             writer.WriteEndObject();
         }
             break;
         case JsonValueType.String:
         {
             writer.WriteValue(value.GetString());
         }
             break;
         default:
             throw new ArgumentOutOfRangeException("ValueType");
     }
 }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:58,代码来源:JsonValueConverter.cs

示例4: ExportValue

        protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
        {
            if (context == null) throw new ArgumentNullException("context");
            if (writer == null) throw new ArgumentNullException("writer");

            writer.WriteStartArray();
            _exporter(context, value, writer);
            writer.WriteEndArray();
        }
开发者ID:RyanWangTHU,项目名称:ccv2,代码行数:9,代码来源:TupleExporter.cs

示例5: ExportValue

        protected override void ExportValue(object value, JsonWriter writer)
        {
            IEnumerable items = (IEnumerable) value;
            
            writer.WriteStartArray();

            foreach (object item in items)
                writer.WriteValue(item);

            writer.WriteEndArray();
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:11,代码来源:EnumerableExporter.cs

示例6: WriteJsonValue

 private void WriteJsonValue(JsonWriter writer, IJsonValue value)
 {
   switch (value.ValueType)
   {
     case JsonValueType.Array:
       {
         JsonArray a = value.GetArray();
         writer.WriteStartArray();
         for (int i = 0; i < a.Count; i++)
         {
           WriteJsonValue(writer, a[i]);
         }
         writer.WriteEndArray();
       }
       break;
     case JsonValueType.Boolean:
       {
         writer.WriteValue(value.GetBoolean());
       }
       break;
     case JsonValueType.Null:
       {
         writer.WriteNull();
       }
       break;
     case JsonValueType.Number:
       {
         writer.WriteValue(value.GetNumber());
       }
       break;
     case JsonValueType.Object:
       {
         JsonObject o = value.GetObject();
         writer.WriteStartObject();
         foreach (KeyValuePair<string, IJsonValue> v in o)
         {
           writer.WritePropertyName(v.Key);
           WriteJsonValue(writer, v.Value);
         }
         writer.WriteEndObject();
       }
       break;
     case JsonValueType.String:
       {
         writer.WriteValue(value.GetString());
       }
       break;
     default:
       throw new ArgumentOutOfRangeException("ValueType");
   }
 }
开发者ID:JeffreyZksun,项目名称:Newtonsoft.Json,代码行数:51,代码来源:JsonValueConverter.cs

示例7: FormatView

        internal static void FormatView(DataView view, JsonWriter writer)
        {
            Debug.Assert(view != null);
            Debug.Assert(writer != null);

            writer.WriteStartObject();

            writer.WriteMember("columns");

            writer.WriteStartArray();
            foreach (DataColumn column in view.Table.Columns)
                writer.WriteValue(column.ColumnName);
            writer.WriteEndArray();

            writer.WriteMember("rows");

            writer.WriteStartArray();
            foreach (DataRowView row in view)
                writer.WriteValue(row.Row.ItemArray);
            writer.WriteEndArray();

            writer.WriteEndObject();
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:23,代码来源:DataViewFormatter.cs

示例8: ExportValue

        protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
        {
            Debug.Assert(context != null);
            Debug.Assert(value != null);
            Debug.Assert(writer != null);

            IEnumerable items = (IEnumerable) value;
            
            writer.WriteStartArray();

            foreach (object item in items)
                context.Export(item, writer);

            writer.WriteEndArray();
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:15,代码来源:EnumerableExporter.cs

示例9: ExportView

        internal static void ExportView(ExportContext context, DataView view, JsonWriter writer)
        {
            Debug.Assert(context != null);
            Debug.Assert(view != null);
            Debug.Assert(writer != null);

            writer.WriteStartObject();

            writer.WriteMember("columns");

            writer.WriteStartArray();
            foreach (DataColumn column in view.Table.Columns)
                context.Export(column.ColumnName, writer);
            writer.WriteEndArray();

            writer.WriteMember("rows");

            writer.WriteStartArray();
            foreach (DataRowView row in view)
                context.Export(row.Row.ItemArray, writer);
            writer.WriteEndArray();

            writer.WriteEndObject();
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:24,代码来源:DataViewExporter.cs

示例10: 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)
    {
      DataTable table = (DataTable)value;

      writer.WriteStartArray();

      foreach (DataRow row in table.Rows)
      {
        writer.WriteStartObject();
        foreach (DataColumn column in row.Table.Columns)
        {
          writer.WritePropertyName(column.ColumnName);
          serializer.Serialize(writer, row[column]);
        }
        writer.WriteEndObject();
      }

      writer.WriteEndArray();
    }
开发者ID:VirtueMe,项目名称:ravendb,代码行数:25,代码来源:DataTableConverter.cs

示例11: 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)
    {
      DataTable table = (DataTable)value;
      DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;

      writer.WriteStartArray();

      foreach (DataRow row in table.Rows)
      {
        writer.WriteStartObject();
        foreach (DataColumn column in row.Table.Columns)
        {
          writer.WritePropertyName((resolver != null) ? resolver.ResolvePropertyName(column.ColumnName) : column.ColumnName);
          serializer.Serialize(writer, row[column]);
        }
        writer.WriteEndObject();
      }

      writer.WriteEndArray();
    }
开发者ID:pmorton,项目名称:Json.Net,代码行数:26,代码来源:DataTableConverter.cs

示例12: SerializeGroupedNodes

    private void SerializeGroupedNodes(JsonWriter writer, IXmlNode node, XmlNamespaceManager manager, bool writePropertyName)
    {
      // group nodes together by name
      Dictionary<string, List<IXmlNode>> nodesGroupedByName = new Dictionary<string, List<IXmlNode>>();

      for (int i = 0; i < node.ChildNodes.Count; i++)
      {
        IXmlNode childNode = node.ChildNodes[i];
        string nodeName = GetPropertyName(childNode, manager);

        List<IXmlNode> nodes;
        if (!nodesGroupedByName.TryGetValue(nodeName, out nodes))
        {
          nodes = new List<IXmlNode>();
          nodesGroupedByName.Add(nodeName, nodes);
        }

        nodes.Add(childNode);
      }

      // loop through grouped nodes. write single name instances as normal,
      // write multiple names together in an array
      foreach (KeyValuePair<string, List<IXmlNode>> nodeNameGroup in nodesGroupedByName)
      {
        List<IXmlNode> groupedNodes = nodeNameGroup.Value;
        bool writeArray;

        if (groupedNodes.Count == 1)
        {
          writeArray = IsArray(groupedNodes[0]);
        }
        else
        {
          writeArray = true;
        }

        if (!writeArray)
        {
          SerializeNode(writer, groupedNodes[0], manager, writePropertyName);
        }
        else
        {
          string elementNames = nodeNameGroup.Key;

          if (writePropertyName)
            writer.WritePropertyName(elementNames);

          writer.WriteStartArray();

          for (int i = 0; i < groupedNodes.Count; i++)
          {
            SerializeNode(writer, groupedNodes[i], manager, false);
          }

          writer.WriteEndArray();
        }
      }
    }
开发者ID:284247028,项目名称:MvvmCross,代码行数:58,代码来源:XmlNodeConverter.cs

示例13: WriteTo

        public override void WriteTo(JsonWriter writer)
        {
            writer.WriteStartArray();

              foreach (JToken token in Children())
              {
            token.WriteTo(writer);
              }

              writer.WriteEndArray();
        }
开发者ID:nhatkycon,项目名称:AoCuoiHongNhung,代码行数:11,代码来源:JArray.cs

示例14: SerializeGroupedNodes

    private void SerializeGroupedNodes(JsonWriter writer, XmlNode node)
    {
      // group nodes together by name
      Dictionary<string, List<XmlNode>> nodesGroupedByName = new Dictionary<string, List<XmlNode>>();

      for (int i = 0; i < node.ChildNodes.Count; i++)
      {
        XmlNode childNode = node.ChildNodes[i];
        string nodeName = GetPropertyName(childNode);

        List<XmlNode> nodes;
        if (!nodesGroupedByName.TryGetValue(nodeName, out nodes))
        {
          nodes = new List<XmlNode>();
          nodesGroupedByName.Add(nodeName, nodes);
        }

        nodes.Add(childNode);
      }

      // loop through grouped nodes. write single name instances as normal,
      // write multiple names together in an array
      foreach (KeyValuePair<string, List<XmlNode>> nodeNameGroup in nodesGroupedByName)
      {
        List<XmlNode> groupedNodes = nodeNameGroup.Value;
        bool writeArray;

        if (groupedNodes.Count == 1)
        {
          XmlNode singleNode = groupedNodes[0];
          XmlAttribute jsonArrayAttribute = (singleNode.Attributes != null) ? singleNode.Attributes["Array", JsonNamespaceUri] : null;
          if (jsonArrayAttribute != null)
            writeArray = XmlConvert.ToBoolean(jsonArrayAttribute.Value);
          else
            writeArray = false;
        }
        else
        {
          writeArray = true;
        }

        if (!writeArray)
        {
          SerializeNode(writer, groupedNodes[0], true);
        }
        else
        {
          string elementNames = nodeNameGroup.Key;
          writer.WritePropertyName(nodeNameGroup.Key);
          writer.WriteStartArray();

          for (int i = 0; i < groupedNodes.Count; i++)
          {
            SerializeNode(writer, groupedNodes[i], false);
          }

          writer.WriteEndArray();
        }
      }
    }
开发者ID:matthewcanty,项目名称:worldpay-lib-dotnet,代码行数:60,代码来源:XmlNodeConverter.cs

示例15: WriteJson

            /// <summary>
            /// Write the JSON string.  This will convert all the properties to a JSON string.
            /// This is done manaully to improve conversion time.  The default serializer will check
            /// each property if it can convert.  This will convert the properties automatically.  This
            /// will double the speed.
            /// 
            /// Newtonsoft.Json.JsonConvert.SerializeObject(ensemble.NmeaData).
            /// 
            /// </summary>
            /// <param name="writer">JSON Writer.</param>
            /// <param name="value">Object to write to JSON.</param>
            /// <param name="serializer">Serializer to convert the object.</param>
            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            {
                // Cast the object
                var data = value as NmeaDataSet;

                // Start the object
                writer.Formatting = Formatting.None;            // Make the text not indented, so not as human readable.  This will save disk space
                writer.WriteStartObject();                      // Start the JSON object

                // Write the base values
                writer.WriteRaw(data.ToJsonBaseStub());
                writer.WriteRaw(",");

                // Write the NMEA strings
                writer.WritePropertyName(DataSet.BaseDataSet.JSON_STR_NMEASTRINGS);
                if (data.NmeaStrings != null)
                {
                    writer.WriteStartArray();
                    for (int x = 0; x < data.NmeaStrings.Count; x++)
                    {
                        writer.WriteValue(data.NmeaStrings[x]);
                    }
                    writer.WriteEndArray();
                }
                else
                {
                    writer.WriteNull();
                }

                // End the object
                writer.WriteEndObject();
            }
开发者ID:Bobfrat,项目名称:RTI,代码行数:44,代码来源:NmeaDataSet.cs


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