• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# JsonTextWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中JsonTextWriter的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter类的具体用法?C# JsonTextWriter怎么用?C# JsonTextWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: TraceJsonReader

 // Token: 0x060002C9 RID: 713
 // RVA: 0x000079B8 File Offset: 0x00005BB8
 public TraceJsonReader(JsonReader innerReader)
 {
     this._innerReader = innerReader;
     this._sw = new StringWriter(CultureInfo.InvariantCulture);
     this._textWriter = new JsonTextWriter(this._sw);
     this._textWriter.Formatting = Formatting.Indented;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:9,代码来源:TraceJsonReader.cs


示例2: ArrayBasicValidation_Pass

        public void ArrayBasicValidation_Pass()
        {
            JSchema schema = new JSchema();
            schema.Type = JSchemaType.Array;
            schema.Items.Add(new JSchema
            {
                Type = JSchemaType.Integer
            });

            SchemaValidationEventArgs a = null;

            StringWriter sw = new StringWriter();
            JsonTextWriter writer = new JsonTextWriter(sw);
            JSchemaValidatingWriter validatingWriter = new JSchemaValidatingWriter(writer);
            validatingWriter.Schema = schema;
            validatingWriter.ValidationEventHandler += (sender, args) => { a = args; };

            validatingWriter.WriteStartArray();
            validatingWriter.WriteValue(10);
            validatingWriter.WriteValue(10);
            validatingWriter.WriteEndArray();

            Assert.IsNull(a);

            Assert.AreEqual("[10,10]", sw.ToString());
        }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:26,代码来源:JSchemaValidatingWriterTests.cs


示例3: EntitiesTest

    public void EntitiesTest()
    {
      Purchase purchase = new Purchase() { Id = 1 };
      purchase.PurchaseLine.Add(new PurchaseLine() { Id = 1, Purchase = purchase });
      purchase.PurchaseLine.Add(new PurchaseLine() { Id = 2, Purchase = purchase });

      StringWriter sw = new StringWriter();
      JsonSerializer serializer = new JsonSerializer();
      serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

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

        serializer.Serialize(jw, purchase);
      }

      string json = sw.ToString();

      Assert.AreEqual(@"{
  ""Id"": 1,
  ""PurchaseLine"": [
    {
      ""Id"": 1,
      ""PurchaseReference"": {
        ""EntityKey"": null,
        ""RelationshipName"": ""EntityDataModel.PurchasePurchaseLine"",
        ""SourceRoleName"": ""PurchaseLine"",
        ""TargetRoleName"": ""Purchase"",
        ""RelationshipSet"": null,
        ""IsLoaded"": false
      },
      ""EntityState"": 1,
      ""EntityKey"": null
    },
    {
      ""Id"": 2,
      ""PurchaseReference"": {
        ""EntityKey"": null,
        ""RelationshipName"": ""EntityDataModel.PurchasePurchaseLine"",
        ""SourceRoleName"": ""PurchaseLine"",
        ""TargetRoleName"": ""Purchase"",
        ""RelationshipSet"": null,
        ""IsLoaded"": false
      },
      ""EntityState"": 1,
      ""EntityKey"": null
    }
  ],
  ""EntityState"": 1,
  ""EntityKey"": null
}", json);

      Purchase newPurchase = JsonConvert.DeserializeObject<Purchase>(json);
      Assert.AreEqual(1, newPurchase.Id);

      Assert.AreEqual(2, newPurchase.PurchaseLine.Count);
      Assert.AreEqual(1, newPurchase.PurchaseLine.ElementAt(0).Id);
      Assert.AreEqual(2, newPurchase.PurchaseLine.ElementAt(1).Id);
    }
开发者ID:thirumg,项目名称:Avro.NET,代码行数:60,代码来源:JsonConvertTest.cs


示例4: Format

 private static string Format(object o)
 {
     JsonTextWriter writer = new JsonTextWriter();
     writer.ValueFormatter = new DateTimeFormatter();
     writer.WriteValue(o);
     return writer.ToString();
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:7,代码来源:TestDateTimeFormatter.cs


示例5: Contracts

        //IEnumerable<T> WhereActiveOrderBy(
        //REFACTOR: we're building things up in memory, and inefficiently as well...
        //MESS: NAIVE: these are nasty messes of code as well.
        public ActionResult Contracts()
        {
            //get a list with the newest employees/offices for each employee/office code.
            var newestOffices = db.newestOffices();
            var newestEmployees = db.newestEmployees();

            return authenticatedAction(new String[] { "UT", "UR" }, () => {
                content:
                var result = makeJSONResult();
                using (JsonTextWriter w = new JsonTextWriter()) {
                    w.WriteStartArray();
                    foreach (Contract c in db.Contracts.WAOBTL()) {
                        w.writeSharedJSONMembers(c);
                        w.writeSharedJSONProlog();
                        foreach (Company co in db.Companies.Where(tco => tco.contractCode == c.code).WAOBTL()) {
                            w.writeSharedJSONMembers(co);
                            w.WriteMember("offices");
                            w.WriteStartArray();
                            foreach (Office o in newestOffices
                                .Where(o => o.companyCode == co.code)
                                .Where(o => o.contractCode == c.code)
                                .WAOBTL()
                                 ) {
                                w.WriteStartObject();
                                //LOOK AT THIS! WE'RE NOT JUST SENDING OVER THE CODE, BUT THE VERSION AS WELL!
                                w.WriteMember("code");
                                w.WriteString(o.code + "?" + o.version.ToString());
                                w.WriteMember("description");
                                w.WriteString(o.description);
                                w.WriteEndObject();
                            }
                            w.WriteEndArray();
                            w.WriteMember("employees");
                            w.WriteStartArray();
                            foreach (Employee e in newestEmployees
                                .Where(e => e.companyCode == co.code)
                                .Where(e => e.contractCode == c.code)
                                .WAOBTL()) {
                                w.WriteStartObject();
                                //LOOK AT THIS! WE'RE NOT JUST SENDING OVER THE CODE, BUT THE VERSION AS WELL!
                                w.WriteMember("code");
                                w.WriteString(e.code + "?" + e.version.ToString());
                                w.WriteMember("description");
                                w.WriteString(e.firstName + " " + e.lastName);
                                w.WriteEndObject();
                            }
                            w.WriteEndArray();
                            w.WriteEndObject();
                        }
                        w.writeSharedJSONEpilog();
                    }
                    w.WriteEndArray();
                    result.Content = w.ToString();
                }
                logger.Debug("TreesController.Contracts accessed.");
                return result;
            });
        }
开发者ID:rplacd,项目名称:RedTelephone,代码行数:61,代码来源:TreesController.cs


示例6: Formatting

 public void Formatting()
 {
     ControlFormatter formatter = new ControlFormatter();
     JsonTextWriter writer = new JsonTextWriter();
     HtmlGenericControl span = new HtmlGenericControl("span");
     span.InnerText = "Happy & shiny people!";
     formatter.Format(span, writer);
     Assert.AreEqual("\"<span\\>Happy &amp; shiny people!</span\\>\"", writer.ToString());
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:9,代码来源:TestControlFormatter.cs


示例7: Example

        public void Example()
        {
            #region Usage
            string schemaJson = @"{
              'description': 'A person',
              'type': 'object',
              'properties': {
                'name': {'type':'string'},
                'hobbies': {
                  'type': 'array',
                  'items': {'type':'string'}
                }
              }
            }";

            Person p = new Person
            {
                Name = "James",
                Hobbies = new List<string>
                {
                    ".NET", "Blogging", "Reading", "Xbox", "LOLCATS"
                }
            };

            StringWriter stringWriter = new StringWriter();
            JsonTextWriter writer = new JsonTextWriter(stringWriter);
            writer.Formatting = Formatting.Indented;

            JSchemaValidatingWriter validatingWriter = new JSchemaValidatingWriter(writer);
            validatingWriter.Schema = JSchema.Parse(schemaJson);

            IList<string> messages = new List<string>();
            validatingWriter.ValidationEventHandler += (o, a) => messages.Add(a.Message);

            JsonSerializer serializer = new JsonSerializer();
            serializer.Serialize(validatingWriter, p);

            Console.WriteLine(stringWriter);
            // {
            //   "Name": "James",
            //   "Hobbies": [
            //     ".NET",
            //     "Blogging",
            //     "Reading",
            //     "Xbox",
            //     "LOLCATS"
            //   ]
            // }

            bool isValid = (messages.Count == 0);

            Console.WriteLine(isValid);
            // true
            #endregion

            Assert.IsTrue(isValid);
        }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:57,代码来源:JsonValidatingWriterAndSerializer.cs


示例8: Create

 /// <summary>
 /// Creates an instance of <see cref="JRaw"/> with the content of the reader's current token.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <returns>An instance of <see cref="JRaw"/> with the content of the reader's current token.</returns>
 public static JRaw Create(JsonReader reader)
 {
     using (var sw = new StringWriter(CultureInfo.InvariantCulture))
     using (var jsonWriter = new JsonTextWriter(sw))
     {
         jsonWriter.WriteToken(reader);
         return new JRaw(sw.ToString());
     }
 }
开发者ID:sat1582,项目名称:CODEFramework,代码行数:14,代码来源:JRaw.cs


示例9: ExactSelection

 public void ExactSelection()
 {
     JsonTextWriter writer = new JsonTextWriter();
     CompositeFormatter compositeFormatter = new CompositeFormatter();
     compositeFormatter.AddFormatter(typeof(object), new TestFormatter());
     IJsonFormatter formatter = compositeFormatter.SelectFormatter(typeof(object));
     formatter.Format(new object(), writer);
     Assert.AreEqual("\"(object)\"", writer.ToString());
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:9,代码来源:TestCompositeFormatter.cs


示例10: Export

 public void Export()
 {
     ControlExporter exporter = new ControlExporter();
     JsonTextWriter writer = new JsonTextWriter();
     HtmlGenericControl span = new HtmlGenericControl("span");
     span.InnerText = "Happy & shiny people!";
     exporter.Export(new ExportContext(), span, writer);
     Assert.AreEqual("[\"<span>Happy &amp; shiny people!<\\/span>\"]", writer.ToString());
 }
开发者ID:bubbafat,项目名称:Hebo,代码行数:9,代码来源:TestControlExporter.cs


示例11: TraceJsonReader

        public TraceJsonReader(JsonReader innerReader)
        {
            _innerReader = innerReader;

            _sw = new StringWriter(CultureInfo.InvariantCulture);
            // prefix the message in the stringwriter to avoid concat with a potentially large JSON string
            _sw.Write("Deserialized JSON: " + Environment.NewLine);

            _textWriter = new JsonTextWriter(_sw);
            _textWriter.Formatting = Formatting.Indented;
        }
开发者ID:GorelH,项目名称:ravendb,代码行数:11,代码来源:TraceJsonReader.cs


示例12: TraceJsonWriter

 // Token: 0x060002DC RID: 732
 // RVA: 0x0002F550 File Offset: 0x0002D750
 public TraceJsonWriter(JsonWriter innerWriter)
 {
     this._innerWriter = innerWriter;
     this._sw = new StringWriter(CultureInfo.InvariantCulture);
     this._textWriter = new JsonTextWriter(this._sw);
     this._textWriter.Formatting = Formatting.Indented;
     this._textWriter.Culture = innerWriter.Culture;
     this._textWriter.DateFormatHandling = innerWriter.DateFormatHandling;
     this._textWriter.DateFormatString = innerWriter.DateFormatString;
     this._textWriter.DateTimeZoneHandling = innerWriter.DateTimeZoneHandling;
     this._textWriter.FloatFormatHandling = innerWriter.FloatFormatHandling;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:14,代码来源:TraceJsonWriter.cs


示例13: Create

		// Token: 0x060005D8 RID: 1496
		// RVA: 0x00035994 File Offset: 0x00033B94
		public static JRaw Create(JsonReader reader)
		{
			JRaw result;
			using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
			{
				using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter))
				{
					jsonTextWriter.WriteToken(reader);
					result = new JRaw(stringWriter.ToString());
				}
			}
			return result;
		}
开发者ID:newchild,项目名称:Project-DayZero,代码行数:15,代码来源:JRaw.cs


示例14: Example

    public void Example()
    {
      JsonSchema schema = JsonSchema.Parse(@"{'type': 'object'}");

      // serialize JsonSchema to a string and then write string to a file
      File.WriteAllText(@"c:\schema.json", schema.ToString());

      // serialize JsonSchema directly to a file
      using (StreamWriter file = File.CreateText(@"c:\schema.json"))
      using (JsonTextWriter writer = new JsonTextWriter(file))
      {
        schema.WriteTo(writer);
      }
    }
开发者ID:che3tah7,项目名称:Newtonsoft.Json,代码行数:14,代码来源:SaveJsonSchemaToFile.cs


示例15: Format

        private static string Format(object o)
        {
            ComponentFormatter componentFormatter = new ComponentFormatter();

            CompositeFormatter compositeFormatter = new CompositeFormatter();
            compositeFormatter.AddFormatter(typeof(Car), componentFormatter);
            compositeFormatter.AddFormatter(typeof(Person), componentFormatter);

            JsonTextWriter writer = new JsonTextWriter();
            writer.ValueFormatter = compositeFormatter;

            writer.WriteValue(o);
            return writer.ToString();
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:14,代码来源:TestComponentFormatter.cs


示例16: Example

        public void Example()
        {
            #region Usage
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = 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();
            }

            Console.WriteLine(sb.ToString());
            // {
            //   "CPU": "Intel",
            //   "PSU": "500W",
            //   "Drives": [
            //     "DVD read/writer"
            //     /*(broken)*/,
            //     "500 gigabyte hard drive",
            //     "200 gigabype hard drive"
            //   ]
            // }
            #endregion

            Assert.AreEqual(@"{
  ""CPU"": ""Intel"",
  ""PSU"": ""500W"",
  ""Drives"": [
    ""DVD read/writer""
    /*(broken)*/,
    ""500 gigabyte hard drive"",
    ""200 gigabype hard drive""
  ]
}", sb.ToString());
        }
开发者ID:b-bot-110,项目名称:Newtonsoft.Json,代码行数:49,代码来源:WriteJsonWithJsonTextWriter.cs


示例17: EndRequest

        public override void EndRequest()
        {
            base.EndRequest();

            Context.Response.ContentType = "application/json";
            
            using (var streamWriter = new StreamWriter(Context.Response.OutputStream))
            using (var writer = new JsonTextWriter(streamWriter))
            {
                writer.WriteStartObject();
                writer.WritePropertyName("c");
                writer.WriteValue(_channelId);
                writer.WriteEndObject();
            }
        }
开发者ID:gmt-europe,项目名称:ProtoChannel,代码行数:15,代码来源:ChannelCreateRequest.cs


示例18: TraceJsonWriter

        public TraceJsonWriter(JsonWriter innerWriter)
        {
            _innerWriter = innerWriter;

            _sw = new StringWriter(CultureInfo.InvariantCulture);
            // prefix the message in the stringwriter to avoid concat with a potentially large JSON string
            _sw.Write("Serialized JSON: " + Environment.NewLine);

            _textWriter = new JsonTextWriter(_sw);
            _textWriter.Formatting = Formatting.Indented;
            _textWriter.Culture = innerWriter.Culture;
            _textWriter.DateFormatHandling = innerWriter.DateFormatHandling;
            _textWriter.DateFormatString = innerWriter.DateFormatString;
            _textWriter.DateTimeZoneHandling = innerWriter.DateTimeZoneHandling;
            _textWriter.FloatFormatHandling = innerWriter.FloatFormatHandling;
        }
开发者ID:Chunshan-Theta,项目名称:Xamarin_WeatherAPP_iOS_Android-,代码行数:16,代码来源:TraceJsonWriter.cs


示例19: CreateFrom

        public static JsonWriter CreateFrom(StreamWriter streamWriter, JsonSerializerSettings settings)
        {
            var jw = new JsonTextWriter(streamWriter);

            // reader/writer specific
            // unset values won't override reader/writer set values
            jw.Formatting = settings.Formatting;
            jw.DateFormatHandling = settings.DateFormatHandling;
            jw.DateTimeZoneHandling = settings.DateTimeZoneHandling;
            jw.DateFormatString = settings.DateFormatString;
            jw.FloatFormatHandling = settings.FloatFormatHandling;
            jw.StringEscapeHandling = settings.StringEscapeHandling;
            jw.Culture = settings.Culture;

            return jw;
        }
开发者ID:thehexgod,项目名称:BESSY-DB,代码行数:16,代码来源:JsonWriterFactory.cs


示例20: Example

    public void Example()
    {
      JObject videogameRatings = new JObject(
        new JProperty("Halo", 9),
        new JProperty("Starcraft", 9),
        new JProperty("Call of Duty", 7.5));

      File.WriteAllText(@"c:\videogames.json", videogameRatings.ToString());

      // write JSON directly to a file
      using (StreamWriter file = File.CreateText(@"c:\videogames.json"))
      using (JsonTextWriter writer = new JsonTextWriter(file))
      {
        videogameRatings.WriteTo(writer);
      }
    }
开发者ID:che3tah7,项目名称:Newtonsoft.Json,代码行数:16,代码来源:WriteToJsonFile.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JsonToken类代码示例发布时间:2022-05-24
下一篇:
C# JsonTextReader类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap