當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。