Newtonsoft.Json.JsonTextWriter.WritePropertyName C# (CSharp) Method

WritePropertyName() public method

Writes the property name of a name/value pair on a JSON object.
public WritePropertyName ( string name ) : void
name string The name of the property.
return void
        public override void WritePropertyName(string name)
        {
            InternalWritePropertyName(name);

            WriteEscapedString(name, _quoteName);

            _writer.Write(':');
        }

Same methods

JsonTextWriter::WritePropertyName ( string name, bool escape ) : void

Usage Example

Esempio n. 1
1
	private string CreateStatusText()
	{
		using (var sw = new StringWriter())
		using (var jsonWriter = new JsonTextWriter(sw))
		{
			jsonWriter.WriteStartObject();
			{
				// Login
				jsonWriter.WritePropertyName("login");
				jsonWriter.WriteStartObject();
				{
					jsonWriter.WritePropertyName("port");
					jsonWriter.WriteValue(LoginServer.Instance.Conf.Login.Port);
				}
				jsonWriter.WriteEndObject();

				// Servers
				jsonWriter.WritePropertyName("servers");
				jsonWriter.WriteStartObject();
				{
					foreach (var server in LoginServer.Instance.ServerList.List)
					{
						// Channels
						jsonWriter.WritePropertyName(server.Name);
						jsonWriter.WriteStartObject();
						{
							foreach (var channel in server.Channels)
							{
								// Channel
								jsonWriter.WritePropertyName(channel.Key);
								jsonWriter.WriteStartObject();
								{
									jsonWriter.WritePropertyName("host");
									jsonWriter.WriteValue(channel.Value.Host);

									jsonWriter.WritePropertyName("port");
									jsonWriter.WriteValue(channel.Value.Port);

									jsonWriter.WritePropertyName("online");
									jsonWriter.WriteValue(channel.Value.Users);

									jsonWriter.WritePropertyName("onlineMax");
									jsonWriter.WriteValue(channel.Value.MaxUsers);

									jsonWriter.WritePropertyName("state");
									jsonWriter.WriteValue(channel.Value.State);
								}
								jsonWriter.WriteEndObject();
							}
						}
						jsonWriter.WriteEndObject();
					}
				}
				jsonWriter.WriteEndObject();
			}
			jsonWriter.WriteEndObject();

			return sw.ToString();
		}
	}
All Usage Examples Of Newtonsoft.Json.JsonTextWriter::WritePropertyName