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


C# JsonTextWriter.Close方法代码示例

本文整理汇总了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);
        }
开发者ID:JackFong,项目名称:OrderQueryOnline,代码行数:27,代码来源:JsonNetActionResult.cs

示例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;
            }
        }
开发者ID:grimcoder,项目名称:ProduceMarketRESTWebAPI,代码行数:32,代码来源:Utils.cs

示例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();
        }
开发者ID:aschuengel,项目名称:EquipmentsAndNotifications,代码行数:30,代码来源:Program.cs

示例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);
        }
开发者ID:qhodedemo,项目名称:UhuruRabbitMQDemo,代码行数:30,代码来源:default.aspx.cs

示例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);
        }
开发者ID:lanneshoa,项目名称:Sandbox,代码行数:27,代码来源:Serialize.cs

示例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();
    }
开发者ID:ichari,项目名称:ichari,代码行数:33,代码来源:JsonHelper.cs

示例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();
 }
开发者ID:sadowskik,项目名称:KendoUI_Playground,代码行数:9,代码来源:KendoJsonSerializer.cs

示例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();
 }
开发者ID:tmds,项目名称:Tmds.SockJS,代码行数:9,代码来源:JsonEncodingTest.cs

示例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();
 }
开发者ID:pombredanne,项目名称:Cayley.Net,代码行数:9,代码来源:ObjectExtensions.cs

示例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());
            }
        }
开发者ID:modulexcite,项目名称:9GUSLauncher,代码行数:56,代码来源:Create.cs

示例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());
            }
        }
开发者ID:mlankenau,项目名称:fauser_export,代码行数:55,代码来源:Program.cs

示例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();

        }
开发者ID:jchannon,项目名称:Tavis.Problem,代码行数:18,代码来源:ProblemDocument.cs

示例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();
                }
            }
        }
开发者ID:ahmetoz,项目名称:Photopia,代码行数:15,代码来源:JsonNetFormatter.cs

示例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();

        }
开发者ID:stephenZh,项目名称:l2net,代码行数:15,代码来源:BotConfig.cs

示例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);
    }
开发者ID:RedBanies3ofThem,项目名称:tradelink.afterlife,代码行数:16,代码来源:JsonTextWriterTest.cs


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