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


C# JObject.WriteTo方法代码示例

本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.WriteTo方法的具体用法?C# JObject.WriteTo怎么用?C# JObject.WriteTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.Linq.JObject的用法示例。


在下文中一共展示了JObject.WriteTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     //TODO: camelCase for javascript serialization
     var size = (Size)value;
     var jo = new JObject {{"width", size.Width}, {"height", size.Height}};
     jo.WriteTo(writer);
 }
开发者ID:boriphuth,项目名称:GooglemapMvc,代码行数:7,代码来源:SizeJsonConverter.cs

示例2: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     //TODO: camelCase for javascript serialization
     var location = (Location)value;
     var jo = new JObject { { "lat", location.Latitude }, { "lng", location.Longitude } };
     jo.WriteTo(writer);
 }
开发者ID:philoushka,项目名称:GooglemapMvc,代码行数:7,代码来源:LocationJsonConverter.cs

示例3: Test_deep

        public void Test_deep()
        {
            var job = new JObject(
                new JProperty("Prop1", 1),
                new JProperty("Prop2", 2),
                new JProperty("Prop3", new JObject(
                    new JProperty("Prop1", 1),
                    new JProperty("Prop2", 2),
                    new JProperty("Prop3", new JObject(
                        new JProperty("Prop1", 1),
                        new JProperty("Prop2", 2),
                        new JProperty("Prop3", 3),
                        new JProperty("Prop4", 4),
                        new JProperty("Prop5", 5),
                        new JProperty("Prop6", 6),
                        new JProperty("Prop7", 7))),
                    new JProperty("Prop4", 4))),
                new JProperty("Prop4", 4),
                new JProperty("Prop5", 5));
            var stm = new MemoryStream();
            using (var wrt = new JsonTextWriter(new StreamWriter(stm)))
                job.WriteTo(wrt);

            var srs = new JsonNodeDeserializer();
            var xml = srs.Deserialize(new StreamReader(new MemoryStream(stm.ToArray())), "application/json");
        }
开发者ID:nxkit,项目名称:nxkit,代码行数:26,代码来源:JsonNodeDeserializerTests.cs

示例4: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			JObject o = new JObject();

			o.Add("$type", value.GetType().AssemblyQualifiedName);

			if( value is Vector2 )
			{
				o.Add("x", ((UnityEngine.Vector2)value).x);
				o.Add("y", ((UnityEngine.Vector2)value).y);
			}
			else if( value is Vector3 )
			{
				o.Add("x", ((UnityEngine.Vector3)value).x);
				o.Add("y", ((UnityEngine.Vector3)value).y);
				o.Add("z", ((UnityEngine.Vector3)value).z);
			}
			else if( value is Vector4 )
			{
				o.Add("x", ((UnityEngine.Vector4)value).x);
				o.Add("y", ((UnityEngine.Vector4)value).y);
				o.Add("z", ((UnityEngine.Vector4)value).z);
				o.Add("w", ((UnityEngine.Vector4)value).w);
			}
			else if( value is Quaternion )
			{
				o.Add("x", ((UnityEngine.Quaternion)value).x);
				o.Add("y", ((UnityEngine.Quaternion)value).y);
				o.Add("z", ((UnityEngine.Quaternion)value).z);
				o.Add("w", ((UnityEngine.Quaternion)value).w);
			}

			o.WriteTo(writer, serializer.Converters.ToArray());
		}
开发者ID:procore3d,项目名称:giles,代码行数:34,代码来源:pb_VectorConverter.cs

示例5: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var jo = new JObject();
     AddAdditionalFields(jo,value);
     foreach (PropertyInfo prop in value.GetType().GetProperties()) {
         if (prop.GetCustomAttribute(typeof(ElasticEPiIgnoreAttribute)) != null)
             continue;
         if (prop.CanRead && !prop.GetIndexParameters().Any()) {
             try {
                 var propValue = prop.GetValue(value);
                 if (propValue != null && jo.GetValue(prop.Name.ToCamelCase()) == null) {
                     jo.Add(prop.Name.ToCamelCase(), JToken.FromObject(propValue, serializer));
                 }
             }
             catch (Exception e) {
                 var icontent = value as IContent;
                 Logger.WriteToLog(
                     icontent != null
                         ? $"Failed to convert IContent to json. IContent information: Name={icontent.Name} Id={icontent.ContentLink.ID} Type={icontent.GetOriginalType().Name} "
                         : "Failed to convert IContent to json", Level.Error, e);
             }
         }
     }
     jo.WriteTo(writer);
 }
开发者ID:kneeclass,项目名称:ElasticEPi,代码行数:25,代码来源:ContentJsonConverter.cs

示例6: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     // TODO: camelCase for javascript serialization
     var point = (Point)value;
     var jo = new JObject { { "x", point.X }, { "y", point.Y } };
     jo.WriteTo(writer);
 }
开发者ID:razormad,项目名称:GooglemapMvc,代码行数:7,代码来源:PointJsonConverter.cs

示例7: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var val = (IColorEffect) value;
            var nameProp = new JProperty("name", val.Name);

            var jobj = new JObject(nameProp);

            var objWriter = jobj.CreateWriter();
            if (value is FixedColor)
            {
                objWriter.WritePropertyName("color");
                serializer.Serialize(objWriter, ((FixedColor) val).Colors[0]);
            }
            if (value is ImageEffect)
            {
                objWriter.WritePropertyName("imageName");
                objWriter.WriteValue(((ImageEffect)value).ImageName);
                objWriter.WritePropertyName("width");
                objWriter.WriteValue(((ImageEffect)value).Width);
            }
            objWriter.WritePropertyName("colors");
            //serializer.Serialize(objWriter, ((ColorFade)val).Colors.Select(c => new JValue(c)));
            serializer.Serialize(objWriter, val.Colors);
            jobj.WriteTo(writer);
        }
开发者ID:JacquiManzi,项目名称:KineticSpectrum,代码行数:25,代码来源:ColorEffectConverter.cs

示例8: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			JObject o = new JObject();

			o.Add("$type", value.GetType().AssemblyQualifiedName);

			Matrix4x4 matrix = (UnityEngine.Matrix4x4)value;

			o.Add("00", matrix[0,0]);
			o.Add("01", matrix[0,1]);
			o.Add("02", matrix[0,2]);
			o.Add("03", matrix[0,3]);

			o.Add("10", matrix[1,0]);
			o.Add("11", matrix[1,1]);
			o.Add("12", matrix[1,2]);
			o.Add("13", matrix[1,3]);

			o.Add("20", matrix[2,0]);
			o.Add("21", matrix[2,1]);
			o.Add("22", matrix[2,2]);
			o.Add("23", matrix[2,3]);

			o.Add("30", matrix[3,0]);
			o.Add("31", matrix[3,1]);
			o.Add("32", matrix[3,2]);
			o.Add("33", matrix[3,3]);

			o.WriteTo(writer, serializer.Converters.ToArray());
		}
开发者ID:procore3d,项目名称:giles,代码行数:30,代码来源:pb_MatrixConverter.cs

示例9: SetContent

 public static void SetContent(string file, JObject data)
 {
     using (TextWriter writer = File.CreateText(file))
     {
         data.WriteTo(new JsonTextWriter(writer));
     }
 }
开发者ID:vtalas,项目名称:cms,代码行数:7,代码来源:FileExts.cs

示例10: SerializeMessage

        public static Message SerializeMessage(JObject json, Message previousMessage)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(ms))
                {
                    using (JsonTextWriter jtw = new JsonTextWriter(sw))
                    {
                        json.WriteTo(jtw);
                        jtw.Flush();
                        sw.Flush();
                        Message result = Message.CreateMessage(MessageVersion.None, null, new RawBodyWriter(ms.ToArray()));
                        if (previousMessage != null)
                        {
                            result.Properties.CopyProperties(previousMessage.Properties);
                            result.Headers.CopyHeadersFrom(previousMessage.Headers);
                            previousMessage.Close();
                        }

                        result.Properties[JsonRpcConstants.JObjectMessageProperty] = json;
                        return result;
                    }
                }
            }
        }
开发者ID:GusLab,项目名称:WCFSamples,代码行数:25,代码来源:JsonRpcHelpers.cs

示例11: WriteTo

        public static void WriteTo(Bundle bundle, JsonWriter writer, bool summary = false)
        {
            if (bundle == null) throw new ArgumentException("Bundle cannot be null");

            JObject result = new JObject();

            result.Add(new JProperty(JsonDomFhirReader.RESOURCETYPE_MEMBER_NAME, "Bundle"));

            if (!String.IsNullOrWhiteSpace(bundle.Title))
                result.Add(new JProperty(BundleXmlParser.XATOM_TITLE, bundle.Title));
            if (SerializationUtil.UriHasValue(bundle.Id)) result.Add(new JProperty(BundleXmlParser.XATOM_ID, bundle.Id));
            if (bundle.LastUpdated != null) 
                result.Add(new JProperty(BundleXmlParser.XATOM_UPDATED, bundle.LastUpdated));

            if (!String.IsNullOrWhiteSpace(bundle.AuthorName))
                result.Add(jsonCreateAuthor(bundle.AuthorName, bundle.AuthorUri));
            if (bundle.TotalResults != null) result.Add(new JProperty(BundleXmlParser.XATOM_TOTALRESULTS, bundle.TotalResults.ToString()));
          
            if (bundle.Links.Count > 0)
                result.Add(new JProperty(BundleXmlParser.XATOM_LINK, jsonCreateLinkArray(bundle.Links)));
            if (bundle.Tags != null && bundle.Tags.Count() > 0)
                result.Add( TagListSerializer.CreateTagCategoryPropertyJson(bundle.Tags));

            var entryArray = new JArray();

            foreach (var entry in bundle.Entries)
                entryArray.Add(createEntry(entry,summary));

            result.Add(new JProperty(BundleXmlParser.XATOM_ENTRY, entryArray));

            result.WriteTo(writer);
        }
开发者ID:ranjancse26,项目名称:fhir-net-api,代码行数:32,代码来源:BundleJsonSerializer.cs

示例12: WriteSchemaFormatSection

        /// <summary>
        /// Generates the "schema format" section.
        /// </summary>
        private void WriteSchemaFormatSection()
        {
            _writer.WriteLine(new Header(2, "Schema format"));
            _writer.WriteLine(new Paragraph("To create a {0}, add the following schema to the resources section of your template.", _schema.Title));

            foreach (var resDefName in _schema.ResourceDefinitions.Keys)
            {
                using (var stringWriter = new StringWriter())
                {
                    using (var json = new JsonTextWriter(stringWriter))
                    {
                        json.Formatting = Formatting.Indented;
                        var resDef = _schema.ResourceDefinitions[resDefName];
                        var root = new JObject();

                        foreach (var prop in resDef.Properties)
                        {
                            // omit non-required objects
                            if (resDef.Required != null && !resDef.Required.Contains(prop.Key))
                                continue;

                            root.Add(JsonSchemaToJToken(prop.Key, prop.Value));
                        }

                        root.WriteTo(json);
                    }

                    // put each resource definition into its own code block
                    _writer.WriteLine(new Codeblock(stringWriter.ToString()));
                }
            }
        }
开发者ID:devigned,项目名称:autorest,代码行数:35,代码来源:ResourceMarkdownWriter.cs

示例13: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var swaggerBase = (SwaggerObjectBase)value;
            switch (swaggerBase.ObjectType)
            {
                case SwaggerObjectType.ReferenceObject:
                    {
                        var swagger = (SwaggerReferenceObject)swaggerBase;
                        var jObject = JObject.FromObject(swagger.Reference, serializer);

                        // Preserve value inside swagger.Token
                        foreach (var k in swagger.Token)
                        {
                            // Overwrite the value if the key is already defined.
                            jObject[k.Key] = k.Value;
                        }

                        jObject.WriteTo(writer);
                    }
                    break;
                case SwaggerObjectType.Object:
                    {
                        var swagger = (SwaggerObject)swaggerBase;
                        var jObject = new JObject();
                        foreach (var i in swagger.Dictionary)
                        {
                            jObject.Add(i.Key, JToken.FromObject(i.Value, serializer));
                        }
                        jObject.WriteTo(writer);
                    }
                    break;
                case SwaggerObjectType.Array:
                    {
                        var swagger = (SwaggerArray)swaggerBase;
                        var jArray = JArray.FromObject(swagger.Array.Select(s => JToken.FromObject(s, serializer)));
                        jArray.WriteTo(writer);
                    }
                    break;
                case SwaggerObjectType.ValueType:
                    {
                        var swagger = (SwaggerValue)swaggerBase;
                        swagger.Token.WriteTo(writer);
                    }
                    break;
                case SwaggerObjectType.LoopReference:
                    {
                        var swagger = (SwaggerLoopReferenceObject)swaggerBase;
                        var jObject = new JObject();
                        foreach (var i in swagger.Dictionary)
                        {
                            jObject.Add(i.Key, JToken.FromObject(i.Value, serializer));
                        }
                        jObject.WriteTo(writer);
                    }
                    break;
                default:
                    throw new NotSupportedException(swaggerBase.ObjectType.ToString());
            }
        }
开发者ID:dotnet,项目名称:docfx,代码行数:59,代码来源:SwaggerObjectConverter.cs

示例14: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     serializer.Converters.Remove(this);
     var root = new JObject();
     ConvertRecursively((IResource)value, root, serializer);
     root.WriteTo(writer);
     serializer.Converters.Add(this);
 }
开发者ID:olohmann,项目名称:Lohmann.HALight,代码行数:8,代码来源:ResourceConverter.cs

示例15: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var policy = (PartitionQosPolicy)value;
     var json = new JObject ();
     json.Add (new JProperty ("id", 2));
     json.Add(new JProperty("vs", new JArray(policy.Values)));
     json.WriteTo (writer);
 }
开发者ID:gitter-badger,项目名称:vortex-xamarin,代码行数:8,代码来源:PartitionQosPolicy.cs


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