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


C# JsonTextWriter.WriteStartArray方法代码示例

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


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

示例1: toJSON

        private static string toJSON(SqlDataReader rdr)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            JsonWriter jsonWriter = new JsonTextWriter(sw);
            jsonWriter.WriteStartArray();
            while (rdr.Read())
            {
                int fieldcount = rdr.FieldCount; // count how many columns are in the row
                object[] values = new object[fieldcount]; // storage for column values
                rdr.GetValues(values); // extract the values in each column
                jsonWriter.WriteStartObject();
                for (int index = 0; index < fieldcount; index++)
                {

                    string colName = rdr.GetName(index);
                    object value = values[index];
                    jsonWriter.WritePropertyName(colName);

                    if (value == DBNull.Value)
                        value = "";
                    else if (colName.Contains("date") && !colName.Contains("by"))
                        value = String.Format("{0:MM/dd/yyyy HH:mm tt}", value);

                    jsonWriter.WriteValue(value);
                }
                jsonWriter.WriteEndObject();
            }
            jsonWriter.WriteEndArray();

            return sb.ToString();
        }
开发者ID:zettasolutions,项目名称:projectWEMS,代码行数:32,代码来源:DataHelper.cs

示例2: WriteTo

        public static void WriteTo(this Item item, JsonTextWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(item.Format));
            writer.WriteValue(Enum.GetName(typeof(SecsFormat), item.Format));
            if (item.Format == SecsFormat.List)
            {
                writer.WritePropertyName(nameof(item.Items));
                writer.WriteStartArray();
                foreach (var subitem in item.Items)
                    subitem.WriteTo(writer);
                writer.WriteEndArray();
            }
            else
            {
                writer.WritePropertyName(nameof(item.Values));

                if (item.Format == SecsFormat.ASCII || item.Format == SecsFormat.JIS8)
                {
                    writer.WriteValue(item.GetValue<string>());
                }
                else
                {
                    writer.WriteStartArray();
                    foreach (var value in item.Values)
                        writer.WriteValue(value);
                    writer.WriteEndArray();
                }
            }
            writer.WriteEndObject();
        }
开发者ID:mkjeff,项目名称:secs4net,代码行数:32,代码来源:JsonExtension.cs

示例3: Join

 //-----------------------------------------------------------------------------------------------------
 public void Join(UserManager.UserClass _user)
 {
     if (_user.Is_Bot != 1)
     {
         _user.sep.Send("[" + (int)ServerOpcode.enter_room + "]");
         StringBuilder sb = new StringBuilder();
         StringWriter sw = new StringWriter(sb);
         using (JsonWriter writer = new JsonTextWriter(sw))
         {
             writer.Formatting = Formatting.None;
             writer.WriteStartArray();
             writer.WriteValue((int)ServerOpcode.room_state);
             writer.WriteStartArray();
             writer.WriteValue(_channel_id);
             writer.WriteValue(_channel_name);
             writer.WriteValue(_channel_password);
             writer.WriteValue(_channel_maxplayers);
             writer.WriteValue(_channel_gamemode);
             writer.WriteValue(_channel_map);
             writer.WriteValue(_channel_avatar_on);
             writer.WriteValue(_channel_max_wind);
             writer.WriteValue(_channel_gp_rate);
             writer.WriteValue(_unk1);
             writer.WriteValue(_unk2);
             writer.WriteValue(_unk3);
             writer.WriteValue(_unk4);
             writer.WriteEndArray();
             writer.WriteEndArray();
         }
         _user.sep.Send(sb.ToString());
     }
     _user.channel = _channel_id;
     RoomPlayer(_user);
 }
开发者ID:JoaquinVautier,项目名称:DragonBound,代码行数:35,代码来源:Channel+-+copia.cs

示例4: WriteAsJson

        public static void WriteAsJson([NotNull] this LayoutBuilder layoutBuilder, [NotNull] TextWriter writer)
        {
            var output = new JsonTextWriter(writer)
            {
                Formatting = Formatting.Indented
            };

            output.WriteStartObject("Layout");
            output.WriteStartArray("Devices");

            foreach (var deviceBuilder in layoutBuilder.Devices)
            {
                output.WriteStartObject();
                output.WritePropertyStringIf("Name", deviceBuilder.DeviceName);
                output.WritePropertyStringIf("Layout", deviceBuilder.LayoutItemPath);

                output.WriteStartArray("Renderings");

                foreach (var renderingBuilder in deviceBuilder.Renderings.Where(r => r.ParentRendering == null))
                {
                    WriteAsJson(output, deviceBuilder, renderingBuilder);
                }

                output.WriteEndArray();
                output.WriteEndObject();
            }

            output.WriteEndArray();
            output.WriteEndObject();
        }
开发者ID:pveller,项目名称:Sitecore.Pathfinder,代码行数:30,代码来源:FormatExtensions.cs

示例5: Execute

        public override bool Execute()
        {
            if (Items.Length == 0)
                throw new ArgumentException("The provided items contained zero entries.");

            if (!Directory.Exists(Path.GetDirectoryName(JsonFileName)))
                Directory.CreateDirectory(Path.GetDirectoryName(JsonFileName));

            JsonSerializer jsonSerializer = new JsonSerializer();
            using (StreamWriter streamWriter = new StreamWriter(JsonFileName))
            {
                using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                {
                    jsonWriter.Formatting = Formatting.Indented;

                    if (Items.Length > 1)
                        jsonWriter.WriteStartArray();

                    foreach (ITaskItem item in Items)
                    {
                        var customMd = item.CloneCustomMetadata();
                        jsonWriter.WriteStartObject();
                        foreach (var key in customMd.Keys)
                        {
                            var mdString = key.ToString();
                            var mdValue = customMd[key].ToString();

                            jsonWriter.WritePropertyName(mdString);

                            // if the value is surrounded in square brackets it's meant to be an array.
                            // split the value into its respective chunks and write it into a JSON array.
                            if (mdValue.Length > 0 && mdValue[0] == '[' && mdValue[mdValue.Length - 1] == ']')
                            {
                                mdValue = mdValue.Substring(1, mdValue.Length - 2);
                                jsonWriter.WriteStartArray();

                                var parts = mdValue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (var part in parts)
                                    jsonWriter.WriteValue(part);

                                jsonWriter.WriteEndArray();
                            }
                            else
                            {
                                jsonWriter.WriteValue(mdValue);
                            }
                        }

                        jsonWriter.WriteEndObject();
                    }

                    if (Items.Length > 1)
                        jsonWriter.WriteEndArray();

                    Log.LogMessage(MessageImportance.High, "Writing {0}.", JsonFileName);
                }
            }

            return true;
        }
开发者ID:lishibo,项目名称:buildtools,代码行数:60,代码来源:WriteItemsToJson.cs

示例6: Get

        //https://webServiceURL/version/devices/deviceLibraryIdentifier/registrations/passTypeIdentifier?passesUpdatedSince=tag
        public HttpResponseMessage Get(string version, string deviceLibraryIdentifier, string passTypeIdentifier, HttpRequestMessage request)
        {
            //List<string> updatedSerialNumbers = new List<string>();
            //updatedSerialNumbers.Add("121212111");

            //Dictionary<string, string> outputDictionary = new Dictionary<string, string>();
            //outputDictionary.Add("lastUpdated", "21/07/2012");
            //outputDictionary.Add("serialNumbers", JsonConvert.SerializeObject(updatedSerialNumbers));

            var response = new HttpResponseMessage(HttpStatusCode.OK);
            //string json = JsonConvert.SerializeObject(outputDictionary);


            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.Indented;

                writer.WriteStartObject();
                writer.WritePropertyName("lastUpdated");
                writer.WriteValue("21/07/2012");
                writer.WritePropertyName("serialNumbers");
                writer.WriteStartArray();
                writer.WriteValue("121212111");
                writer.WriteEndArray();
                writer.WriteEndObject();
            }

            response.Content = new StringContent(sb.ToString(), Encoding.UTF8, "application/json");

            return response;
        }
开发者ID:shanselman,项目名称:dotnet-passbook,代码行数:35,代码来源:PassRegistrationController.cs

示例7: StringWriter

 void do确定_Click(object sender, EventArgs e)
 {
     var __sw = new StringWriter();
     JsonWriter __writer = new JsonTextWriter(__sw);
     __writer.WriteStartArray();
     foreach (DataGridViewRow __行 in this.out值.Rows)
     {
         if (!__行.IsNewRow)
         {
             var __value = __行.Cells[0].Value == null ? "" : __行.Cells[0].Value.ToString();
             if (_元数据 != null)
             {
                 switch (_元数据.类型)
                 {
                     case "string":
                     case "字符串":
                         __writer.WriteValue(__value);
                         break;
                     default:
                         __writer.WriteRawValue(__value);
                         break;
                 }
             }
             else
             {
                 __writer.WriteRawValue(__value);
             }
         }
     }
     __writer.WriteEndArray();
     __writer.Flush();
     _值 = __sw.GetStringBuilder().ToString();
     this.DialogResult = DialogResult.OK;
 }
开发者ID:xiaomiwk,项目名称:K_tongyongfangwen,代码行数:34,代码来源:F列结构_编辑.cs

示例8: ToJSONRepresentation

        public String ToJSONRepresentation()
        {
            StringBuilder sb = new StringBuilder();
            JsonWriter jw = new JsonTextWriter(new StringWriter(sb));

            jw.Formatting = Formatting.Indented;
            jw.WriteStartObject();
            jw.WritePropertyName(this._description);
            jw.WriteStartArray();

            foreach(MailStructure mail in this._mailStructures)
            {
                jw.WriteStartObject();
                jw.WritePropertyName("Id");
                jw.WriteValue(mail.Id);
                jw.WritePropertyName("Uuid");
                jw.WriteValue(mail.Uuid);
                jw.WritePropertyName("MailDate");
                jw.WriteValue(mail.MailDate);
                jw.WritePropertyName("From");
                jw.WriteValue(mail.From);
                jw.WritePropertyName("Subject");
                jw.WriteValue(mail.Subject);
                jw.WritePropertyName("Body");
                jw.WriteValue(mail.Body);
                jw.WritePropertyName("AttachmentExist");
                jw.WriteValue((mail.AttachmentExist ? "1" : "0"));
                jw.WritePropertyName("AttachmentFiles");
                jw.WriteValue(mail.AttachmentFiles);
                jw.WriteEndObject();
            }
            jw.WriteEndArray();
            jw.WriteEndObject();
            return sb.ToString();
        }
开发者ID:shestakovg,项目名称:mail1c,代码行数:35,代码来源:MailJsonSerializer.cs

示例9: ToJson

 internal string ToJson()
 {
     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
     {
         using (JsonWriter jw = new JsonTextWriter(sw))
         {
             jw.WriteStartObject();
             if (!string.IsNullOrEmpty(AreaType))
             {
                 jw.WritePropertyName("areaType");
                 jw.WriteValue(AreaType);
             }
             if (!string.IsNullOrEmpty(BufferUnits))
             {
                 jw.WritePropertyName("bufferUnits");
                 jw.WriteValue(BufferUnits);
             }
             if (BufferRadii != null && BufferRadii.Count > 0)
             {
                 jw.WritePropertyName("Drives");
                 jw.WriteStartArray();
                 foreach (var radius in BufferRadii)
                     jw.WriteValue(radius);
                 jw.WriteEndArray();
             }
             jw.WriteEndObject();
         }
     }
     return sb.ToString();
 }
开发者ID:jNery,项目名称:geoenrichment_wp8,代码行数:31,代码来源:StudyAreaOptions.cs

示例10: BasicRequest

		//JsonWriter writer = new JsonTextWriter();
		protected static string BasicRequest(int requestID, string method, string sessionID, params string[] parameters)
		{
			StringBuilder sb = new StringBuilder();
			StringWriter sw = new StringWriter(sb);

			using (JsonWriter writer = new JsonTextWriter(sw))
			{
				writer.Formatting = Formatting.Indented;

				writer.WriteStartObject();
				writer.WritePropertyName("jsonrpc");
				writer.WriteValue("2.0");
				writer.WritePropertyName("id");
				writer.WriteValue(requestID);
				writer.WritePropertyName("method");
				writer.WriteValue(method);
				writer.WritePropertyName("params");
				writer.WriteStartArray();
				writer.WriteValue(sessionID);
				foreach (var p in parameters)
					writer.WriteValue(p);
				writer.WriteEndArray();
				writer.WriteEndObject();
                return sb.ToString();
				//return sb.ToString().Replace("\n","");
			}
		}
开发者ID:Jazzeroki,项目名称:LacunaExpressXamarin,代码行数:28,代码来源:CoreClass.cs

示例11: Main

 static void Main(string[] args)
 {
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     using (JsonWriter writer = new JsonTextWriter(sw))
     {
         writer.Formatting = Newtonsoft.Json.Formatting.Indented;
         writer.WriteStartObject();
         writer.WritePropertyName("CPU");
         writer.WriteValue("Intel");
         writer.WritePropertyName("PSU");
         writer.WriteValue("500W");
         writer.WritePropertyName("Drives");
         writer.WriteStartArray();
         writer.WriteValue("DVD read/writer");
         writer.WriteComment("(broken)");
         writer.WriteValue("500 gigabyte hard drive");
         writer.WriteValue("200 gigabype hard drive");
         writer.WriteEnd();
         writer.WriteEndObject();
     }
     File.WriteAllText(Environment.CurrentDirectory + "/rhcdata.json", sw.ToString());
     Console.WriteLine(sw.ToString());
     Console.ReadLine();
 }
开发者ID:MaurodeLyon,项目名称:Huiswerk-CSharp,代码行数:25,代码来源:Program.cs

示例12: Execute

			public override void Execute(object parameter)
			{
				var saveFile = new SaveFileDialog
				{
					DefaultExt = ".raven.dump",
					Filter = "Raven Dumps|*.raven.dump"
				};
				var dialogResult = saveFile.ShowDialog() ?? false;

				if (!dialogResult)
					return;

				stream = saveFile.OpenFile();
				gZipStream = new GZipStream(stream, CompressionMode.Compress);
				streamWriter = new StreamWriter(gZipStream);
				jsonWriter = new JsonTextWriter(streamWriter)
				{
					Formatting = Formatting.Indented
				};

				output(string.Format("Exporting to {0}", saveFile.SafeFileName));

				output("Begin reading indexes");

				jsonWriter.WriteStartObject();
				jsonWriter.WritePropertyName("Indexes");
				jsonWriter.WriteStartArray();

				ReadIndexes(0).Catch(exception => Infrastructure.Execute.OnTheUI(() => Finish(exception)));
			}
开发者ID:emertechie,项目名称:ravendb,代码行数:30,代码来源:ExportTask.cs

示例13: Msj

        public static string Msj(string _msjx, UserManager.UserClass _user)
        {
            string msj_f = HttpUtility.HtmlEncode(_msjx.Replace("\\\"", "\""));
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.None;
                writer.WriteStartArray();
                writer.WriteValue((int)ServerOpcode.chat);
                writer.WriteValue(_msjx);
                writer.WriteValue(_user.Name);

                if(_user.rank >= 24)
                    writer.WriteValue(ChatType.CHAT_TYPE_GM); //type
                else
                    writer.WriteValue(0); //type

                if (_user.guild > 0)
                    writer.WriteValue(_user.guild_name);

                writer.WriteEndArray();
            }

            return sb.ToString();
        }
开发者ID:JoaquinVautier,项目名称:DragonBound,代码行数:26,代码来源:ChatManager.cs

示例14: Serialize

        public override string Serialize(Node node, Type typeAttr)
        {
            XpcaProxy proxy = new XpcaProxy(node);
            StringWriter sw = new StringWriter();

            using(JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = Newtonsoft.Json.Formatting.None;
                jsonWriter.WriteStartObject();

                foreach (KeyValuePair<string, PropertyInfo> property in proxy.GetPropertiesFor(typeAttr)) {
                    object value = proxy[property.Key];

                    if (value != null) {
                        jsonWriter.WritePropertyName(property.Key);
                        if(value is IEnumerable<object>) {
                            jsonWriter.WriteStartArray();

                            foreach (object obj in (value as IEnumerable<object>)) {
                                JsonWriteValue(jsonWriter, obj);
                            }

                            jsonWriter.WriteEndArray();
                        }
                        else {
                            JsonWriteValue(jsonWriter, value);
                        }
                    }
                }
                jsonWriter.WriteEndObject();
            }

            return sw.ToString();
        }
开发者ID:flipback,项目名称:Galilei,代码行数:34,代码来源:JsonSerializer.cs

示例15: ProcessRequest

 public void ProcessRequest(HttpContext context)
 {
     string reVal = string.Empty;
     context.Response.ContentType = "text/plain";
     IEnumerable<ADM_USER> list = from m in etMgr.ADM_USER.OfType<ADM_USER>()
                                  select m;
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     using (JsonWriter jsonWriter = new JsonTextWriter(sw))
     {
         jsonWriter.Formatting = Formatting.Indented;
         jsonWriter.WriteStartArray();
         foreach (ADM_USER m in list)
         {
             jsonWriter.WriteStartObject();
             jsonWriter.WritePropertyName("name");
             jsonWriter.WriteValue(string.IsNullOrEmpty(m.REAL_NAME) ? m.USERNAME : m.REAL_NAME);
             jsonWriter.WritePropertyName("id");
             jsonWriter.WriteValue(m.USER_ID);
             jsonWriter.WriteEndObject();
         }
         jsonWriter.WriteEnd();
     }
     reVal = sb.ToString();
     context.Response.Write(reVal);
 }
开发者ID:mxm2005,项目名称:oacrm,代码行数:26,代码来源:GetUsers.ashx.cs


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