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


C# JsonTextWriter类代码示例

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


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


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