本文整理汇总了C#中Newtonsoft.Json.JsonTextWriter.WriteEndObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteEndObject方法的具体用法?C# JsonTextWriter.WriteEndObject怎么用?C# JsonTextWriter.WriteEndObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteEndObject方法的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();
}
示例2: Serialize
public string Serialize()
{
var sb = new StringBuilder();
var sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("public");
jsonWriter.WriteValue(true);
jsonWriter.WritePropertyName("files");
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName(File);
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("content");
jsonWriter.WriteValue(Code);
jsonWriter.WriteEndObject();
jsonWriter.WriteEndObject();
jsonWriter.WriteEndObject();
}
return sb.ToString();
}
示例3: parameterFieldMapJson
/// <summary>
/// Convert parameter list to json object
/// </summary>
public static string parameterFieldMapJson(parameters parms, string ProjectID, string QueryID)
{
StringWriter sw = new StringWriter();
JsonTextWriter json = new JsonTextWriter(sw);
json.WriteStartObject();
json.WritePropertyName("results");
json.WriteStartArray();
json.WriteStartObject();
// ProjectID and QueryID
json.WritePropertyName("ProjectID");
json.WriteValue(ProjectID);
json.WritePropertyName("QueryID");
json.WriteValue(QueryID);
json.WritePropertyName("parameters");
json.WriteRawValue(JsonConvert.SerializeObject(parms));
json.WriteEndObject();
json.WriteEndArray();
json.WriteEndObject();
json.Flush();
sw.Flush();
return sw.ToString();
}
示例4: ToJson
/// <summary>
/// Serializes <see cref="Graphic"/> into JSON string.
/// </summary>
/// <param name="graphic">graphic to serialize into JSON.</param>
/// <returns>string representation of the JSON object.</returns>
public static string ToJson(this Graphic graphic)
{
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
{
using (JsonWriter jw = new JsonTextWriter(sw))
{
if (graphic.Geometry != null)
{
jw.WriteStartObject();
jw.WritePropertyName("geometry");
// Gets the JSON string representation of the Geometry.
jw.WriteRawValue(graphic.Geometry.ToJson());
jw.WriteEndObject();
}
if (graphic.Attributes.Count > 0)
{
jw.WriteStartObject();
foreach (var item in graphic.Attributes)
{
jw.WritePropertyName(item.Key);
jw.WriteValue(item.Value);
}
jw.WriteEndObject();
}
}
return sb.ToString();
}
}
示例5: DataTableToJSON
public static string DataTableToJSON(DataTable dt, string dtName)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jw = new JsonTextWriter(sw))
{
JsonSerializer ser = new JsonSerializer();
jw.WriteStartObject();
jw.WritePropertyName(dtName);
jw.WriteStartArray();
foreach (DataRow dr in dt.Rows)
{
jw.WriteStartObject();
foreach (DataColumn dc in dt.Columns)
{
jw.WritePropertyName(dc.ColumnName);
ser.Serialize(jw, dr[dc].ToString());
}
jw.WriteEndObject();
}
jw.WriteEndArray();
jw.WriteEndObject();
sw.Close();
jw.Close();
}
return sb.ToString();
}
示例6: GenerateJson
/// <summary>
/// Generate the json output for the page.
/// </summary>
/// <param name="page">
/// The page.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
public static string GenerateJson(IContent page)
{
string json;
List<KeyValuePair<string, string>> propertyValues = page.GetPropertyValues();
StringBuilder stringBuilder = new StringBuilder();
using (StringWriter sw = new StringWriter(stringBuilder, CultureInfo.InvariantCulture))
{
JsonWriter jsonWriter = new JsonTextWriter(sw) { Formatting = Formatting.Indented };
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName(page.Name);
jsonWriter.WriteStartObject();
foreach (KeyValuePair<string, string> content in propertyValues)
{
jsonWriter.WritePropertyName(content.Key);
jsonWriter.WriteValue(TextIndexer.StripHtml(content.Value, content.Value.Length));
}
jsonWriter.WriteEndObject();
jsonWriter.WriteEndObject();
json = sw.ToString();
}
return json;
}
示例7: 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();
}
示例8: 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();
}
示例9: ToJsonString
/// <summary>
/// Serialize this phase to JSON.
/// </summary>
/// <returns>The phase as a JSON string.</returns>
public string ToJsonString()
{
/*
* NB: JsonTextWriter is guaranteed to close the StringWriter
* https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/JsonTextWriter.cs#L150-L160
*/
var sb = new StringBuilder();
var sw = new StringWriter(sb);
using (JsonWriter writer = new JsonTextWriter(sw))
{
writer.WriteStartObject();
writer.WritePropertyName(PhaseType);
// phase start
writer.WriteStartObject();
WriteJson(writer);
writer.WriteProperty("keep", keep);
writer.WriteEndObject();
// phase end
writer.WriteEndObject();
}
return sb.ToString();
}
示例10: CreateStatusText
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();
}
}
示例11: Start
public bool Start(string context)
{
this.context = context;
string uri = baseURI + @"start/";
string method = "POST";
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("context");
jsonWriter.WriteValue(this.context);
jsonWriter.WritePropertyName("participants");
jsonWriter.WriteStartArray();
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("name");
// use the current window user
jsonWriter.WriteValue(Environment.UserName);
jsonWriter.WritePropertyName("id");
// use the computer name + windows user name
jsonWriter.WriteValue(Environment.MachineName + "-" + Environment.UserName);
jsonWriter.WriteEndObject();
jsonWriter.WriteEnd();
jsonWriter.WriteEndObject();
}
string json = sb.ToString();
HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
req.KeepAlive = false;
req.Method = method;
byte[] buffer = Encoding.ASCII.GetBytes(json);
req.ContentLength = buffer.Length;
req.ContentType = "application/json";
Stream PostData = req.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
StreamReader tr = new StreamReader(resp.GetResponseStream());
json = tr.ReadToEnd();
Dictionary<string, string> respValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
if (respValues.ContainsKey("status") && respValues["status"] == "success")
{
this.dialogueID = respValues["dlg_id"];
this.IsRunning = true;
return true;
}
return false;
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
var oSB = new StringBuilder();
var oSW = new StringWriter(oSB);
using (JsonWriter oWriter = new JsonTextWriter(oSW))
{
oWriter.Formatting = Formatting.Indented;
oWriter.WriteStartObject();
if (IsAuthenticated && ApplicationContext.IsStaff)
{
oWriter.WritePropertyName("results");
oWriter.WriteStartArray();
if (!string.IsNullOrEmpty(Request.QueryString["q"]))
{
var sQuery = Request.QueryString["q"];
DataAccess.Log = new DebugTextWriter();
var oResults = DataAccess.fn_Producer_GetCustomerLookup();
oResults = oResults.Where(row => (row.FirstName + " " + row.LastName + " (" + row.Username + ")").Contains(sQuery))
.Distinct().Take(30);
foreach (var oResult in oResults)
{
oWriter.WriteStartObject();
oWriter.WritePropertyName("id");
oWriter.WriteValue(oResult.MPUserID.ToString());
oWriter.WritePropertyName("name");
oWriter.WriteValue(string.Format("{0} {1} ({2})", oResult.FirstName, oResult.LastName, oResult.Username));
oWriter.WriteEndObject();
}
oWriter.WriteEnd();
}
}
oWriter.WriteEndObject();
}
Response.ContentType = "application/json";
Response.Write(oSB.ToString());
Response.End();
}
示例13: 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;
}
示例14: 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;
}
示例15: 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","");
}
}