本文整理汇总了C#中Newtonsoft.Json.JsonTextWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.Close方法的具体用法?C# JsonTextWriter.Close怎么用?C# JsonTextWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
JsonSerializer json = new JsonSerializer();
json.NullValueHandling = NullValueHandling.Ignore;
json.ObjectCreationHandling = ObjectCreationHandling.Replace;
json.MissingMemberHandling = MissingMemberHandling.Ignore;
json.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
String output = String.Empty;
StringWriter sw = new StringWriter();
JsonTextWriter writer = new JsonTextWriter(sw);
writer.Formatting = Formatting.Indented;
writer.QuoteChar = '"';
json.Serialize(writer, this.Data);
output = sw.ToString();
writer.Close();
sw.Close();
context.HttpContext.Response.ContentType = "application/json";
context.HttpContext.Response.Write(output);
}
示例2: SaveToFile
public static void SaveToFile()
{
try
{
JsonSerializer serializer = new JsonSerializer();
var prices = dataAccess.GetAllPrices();
var sales = dataAccess.GetAllSales();
var priceChanges = dataAccess.GetPriceChanges();
string path = DataDir + "\\Prices.json";
var writer = new JsonTextWriter(File.CreateText(path));
serializer.Serialize(writer, prices);
writer.Close();
path = DataDir + "\\Sales.json";
writer = new JsonTextWriter(File.CreateText(path));
serializer.Serialize(writer, sales);
writer.Close();
path = DataDir + "\\priceChanges.json ";
writer = new JsonTextWriter(File.CreateText(path));
serializer.Serialize(writer, priceChanges);
writer.Close();
}
catch (Exception iException)
{
int x = 10;
throw;
}
}
示例3: Main
static void Main(string[] args)
{
// Set connection parameters
var parameters = new RfcConfigParameters();
parameters[RfcConfigParameters.Client] = "050";
parameters[RfcConfigParameters.Language] = "DE";
parameters[RfcConfigParameters.User] = "SCHUENGE";
parameters[RfcConfigParameters.Password] = "";
parameters[RfcConfigParameters.MessageServerHost] = "sawitk80.ceu.heidelberg.com";
parameters[RfcConfigParameters.MessageServerService] = "3641";
parameters[RfcConfigParameters.Name] = "K80";
parameters[RfcConfigParameters.SystemID] = "K80";
parameters[RfcConfigParameters.LogonGroup] = "K80001";
// Get destination (i.e. connection to SAP ERP system)
var destination = RfcDestinationManager.GetDestination(parameters);
JsonWriter writer = new JsonTextWriter(new StreamWriter("test.json"));
writer.Formatting = Formatting.Indented;
writer.WriteStartObject();
var customerNumber = "0080300010";
ReadCustomerContacts(customerNumber, destination, writer);
ReadCustomerEquipments(customerNumber, destination, writer);
writer.WriteEndObject();
writer.Close();
}
示例4: btnSend_Click
protected void btnSend_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
JsonWriter jsonWriter = new JsonTextWriter(sw);
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("name");
jsonWriter.WriteValue(txtName.Text);
jsonWriter.WritePropertyName("description");
jsonWriter.WriteValue(txtDesc.Text);
jsonWriter.WritePropertyName("priority");
jsonWriter.WriteValue((dpdPri.Text).ToUpper());
jsonWriter.WriteEndObject();
string output = sw.ToString();
jsonWriter.Close();
sw.Close();
//string[] args = new string[3];
//args[0] = txtName.Text;
//args[1] = txtDesc.Text;
//args[2] = txtPri.Text;
//string message = string.Join(" ", args);
byte[] body = System.Text.Encoding.UTF8.GetBytes(output);
producer.SendMessage(body);
}
示例5: ToJson
public static string ToJson(object value)
{
Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer()
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Auto,
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
};
StringWriter sw = new StringWriter();
Newtonsoft.Json.JsonTextWriter writer = new JsonTextWriter(sw);
writer.Formatting = Formatting.None;
//writer.QuoteChar = '"';
json.Serialize(writer, value);
string output = sw.ToString();
writer.Close();
sw.Close();
return output;
//JavaScriptSerializer jss = new JavaScriptSerializer();
//return jss.Serialize(value);
}
示例6: 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();
}
示例7: Serialize
public string Serialize(object @object )
{
var serializer = new JsonSerializer();
var stringWriter = new StringWriter();
var writer = new JsonTextWriter(stringWriter) {QuoteName = false, Formatting = Formatting.None};
serializer.Serialize(writer, @object);
writer.Close();
return stringWriter.ToString();
}
示例8: NewtonsoftEncode
private static string NewtonsoftEncode(string input)
{
var sb = new StringBuilder();
var sw = new StringWriter(sb);
JsonWriter writer = new JsonTextWriter(sw);
writer.WriteValue(input);
writer.Close();
return sb.ToString();
}
示例9: ToEmitString
public static string ToEmitString(this object data)
{
var serializer = new JsonSerializer();
var stringWriter = new StringWriter();
var writer = new JsonTextWriter(stringWriter) { QuoteName = false };
serializer.Serialize(writer, data);
writer.Close();
return stringWriter.ToString();
}
示例10: File
public static void File(string fileName, eventVar _eventVar)
{
try
{
//Import config variables
Config.softwareConfig cfg = new Config.softwareConfig();
if (System.IO.File.Exists(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted"))
{
System.IO.File.Delete(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted", FileMode.CreateNew))
using (StreamWriter sw = new StreamWriter(fs))
using (JsonWriter jw = new JsonTextWriter(sw))
{
jw.Formatting = Formatting.Indented;
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(jw, _eventVar);
jw.Close();
sw.Close();
fs.Close();
}
string json = System.IO.File.ReadAllText(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
string encryptJson = CryptoService.Load.Encrypt(json, cfg.cipherKey);
System.IO.File.WriteAllText(MainWindow.workingDir + "\\Config\\" + fileName, encryptJson);
System.IO.File.Delete(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
}
else
{
using (FileStream fs = System.IO.File.Open(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted", FileMode.CreateNew))
using (StreamWriter sw = new StreamWriter(fs))
using (JsonWriter jw = new JsonTextWriter(sw))
{
jw.Formatting = Formatting.Indented;
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(jw, _eventVar);
jw.Close();
sw.Close();
fs.Close();
string json = System.IO.File.ReadAllText(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
string encryptJson = CryptoService.Load.Encrypt(json, cfg.cipherKey);
System.IO.File.WriteAllText(MainWindow.workingDir + "\\Config\\" + fileName, encryptJson);
System.IO.File.Delete(MainWindow.workingDir + "\\Config\\" + fileName + "decrypted");
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
示例11: Main
static void Main(string[] args)
{
String connectionString =
//"user id=mes;" +
//"password=mes;" +
"Trusted_Connection=True;" +
"server=marcus-pc\\SQLEXPRESS;" +
"database=isdata; " +
"connection timeout=5";
Console.WriteLine("start exporting");
try
{
using (FileStream fs = new FileStream("\\\\VBOXSVR\\Shared\\export.json", FileMode.Create, FileAccess.Write))
{
StreamWriter sw = new StreamWriter(fs);
JsonWriter writer = new JsonTextWriter(sw);
writer.Formatting = Formatting.Indented;
writer.WriteStartObject();
writer.WritePropertyName("customers");
BaseExporter export = new ExportCustomer(connectionString, writer);
export.Export();
writer.WritePropertyName("parts");
export = new ExportParts(connectionString, writer);
export.Export();
writer.WritePropertyName("offerings");
export = new ExportOfferings(connectionString, writer);
export.Export();
writer.WritePropertyName("orders");
export = new ExportOrders(connectionString, writer);
export.Export();
writer.WritePropertyName("deliveries");
export = new ExportDeliveries(connectionString, writer);
export.Export();
writer.WritePropertyName("invoices");
export = new ExportInvoices(connectionString, writer);
export.Export();
writer.WriteEndObject();
writer.Close();
sw.Close();
}
}
catch (Exception e)
{
Console.WriteLine("ohh shit: " + e.ToString());
}
}
示例12: Save
/// <summary>
/// Serialize current problem document as JSON representation
/// </summary>
/// <param name="stream"></param>
public void Save(System.IO.MemoryStream stream)
{
var sb = new StringBuilder();
var sw = new StringWriter(sb);
var jsonWriter = new JsonTextWriter(sw) {Formatting = Formatting.Indented};
WriteProblem(jsonWriter);
var stw = new StreamWriter(stream);
stw.Write(sb.ToString());
stw.Flush();
jsonWriter.Close();
}
示例13: SerializeStream
private void SerializeStream(Stream stream, object value)
{
JsonSerializer jsonSerializer = JsonSerializer.Create(_jsonSerializerSettings);
using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
{
using (var jsonTextWriter = new JsonTextWriter(streamWriter))
{
jsonSerializer.Serialize(jsonTextWriter, value);
jsonTextWriter.Flush();
jsonTextWriter.Close();
}
}
}
示例14: Save
public static void Save(string path)
{
if (instance == null)
{
instance = new BotConfig();
}
JsonTextWriter writer = new JsonTextWriter(new StreamWriter(path));
JsonSerializer serializer = new JsonSerializer();
serializer.Formatting = Formatting.Indented;
serializer.Serialize(writer, instance);
writer.Close();
}
示例15: CloseOutput
public void CloseOutput()
{
MemoryStream ms = new MemoryStream();
JsonTextWriter writer = new JsonTextWriter(new StreamWriter(ms));
Assert.IsTrue(ms.CanRead);
writer.Close();
Assert.IsFalse(ms.CanRead);
ms = new MemoryStream();
writer = new JsonTextWriter(new StreamWriter(ms)) { CloseOutput = false };
Assert.IsTrue(ms.CanRead);
writer.Close();
Assert.IsTrue(ms.CanRead);
}