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


C# JsonWriter.WriteToken方法代码示例

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


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

示例1: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var pair = (SwaggerOperationsExtended)value;

            writer.WriteStartObject();
            var count = pair.Keys.Count;
            for (var i = 0; i < count; i++)
            {
                var key = pair.Keys.ElementAt(i);
                var oVal = pair.Values.ElementAt(i);
                
                writer.WritePropertyName(key.ToString().ToLower());

                var tokenReader = new JTokenReader(JToken.FromObject(oVal));
                writer.WriteToken(tokenReader);
            }
            writer.WriteEndObject();
        }
开发者ID:TiandaoStudy,项目名称:Abp.Swagger.Example,代码行数:18,代码来源:SwaggerOperationsExtendedConverter.cs

示例2: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var d = value as LazyDocument;
			if (d == null || d._Value == null)
				return;
			writer.WriteToken(d._Value.CreateReader());
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:7,代码来源:LazyDocumentJsonConverter.cs

示例3: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			writer.WriteToken(JsonToken.String, ((ThrowResult)value).ToString());
		}
开发者ID:xoposhiy,项目名称:design-course,代码行数:4,代码来源:ThrowJsonConverter.cs

示例4: WriteJson

            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            {
                if (value.GetType().BaseType == typeof(Array))
                {

                    writer.WriteStartArray();

                    foreach (object o in (Array)value)
                    {
                        writer.WriteStartObject();
                        try
                        {

                            string[] fields = (string[])GetPropValue(o, "fields");
                            foreach (string field in fields)
                            {

                                var prop = GetPropValue(o, field);
                                if (prop != null)
                                {

                                    writer.WritePropertyName(field);
                                    try
                                    {
                                        writer.WriteValue(prop);
                                    }
                                    catch (Exception exp1)
                                    {
                                        writer.WriteValue(JsonConvert.SerializeObject(prop));
                                    }
                                }
                            }

                        }
                        catch (Exception exp)
                        {

                        }
                        writer.WriteEndObject();

                    }
                    writer.WriteEndArray();
                }
                else
                {

                    try
                    {

                        string[] fields = (string[])GetPropValue(value, "fields");
                        writer.WriteStartObject();
                        foreach (string field in fields)
                        {

                            var prop = GetPropValue(value, field);
                            if (prop != null)
                            {

                                writer.WritePropertyName(field);
                                try
                                {
                                    writer.WriteValue(prop);
                                }
                                catch (Exception exp1)
                                {
                                    writer.WriteValue(JsonConvert.SerializeObject(prop));
                                }
                            }
                        }
                        writer.WriteEndObject();
                    }
                    catch (Exception exp)
                    {
                        JToken j = JToken.FromObject(value);

                        writer.WriteToken(j.CreateReader());
                    }

                }
            }
开发者ID:kioltk,项目名称:mvc,代码行数:80,代码来源:JsonNetResult.cs

示例5: WriteJson

        /// <summary>Writes the JSON representation of the object.</summary>
        /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var contract = serializer.ContractResolver.ResolveContract(value.GetType());
            contract.Converter = null;

            var jObject = JObject.FromObject(value, serializer);
            jObject.AddFirst(new JProperty(_discriminator, value.GetType().Name));
            writer.WriteToken(jObject.CreateReader());

            contract.Converter = this;
        }
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:15,代码来源:JsonInheritanceConverter.cs

示例6: WriteJson

        public override void WriteJson(JsonWriter w, object o, JsonSerializer s)
        {
            var result = "";
            if (o is byte[])
            {
                result += "data:application/octet-stream;base64,";
                result += Convert.ToBase64String((byte[])o);
            }
            else if (o is string)
            {
                result += "data:text/plain;base64,";
                result += Convert.ToBase64String(Encoding.UTF8.GetBytes((string)o));
            }
            else if (o is Bitmap)
            {
                result += "data:image/png;base64,";
                var bmp = (Bitmap) o;
                var stream = new MemoryStream();
                bmp.Save(stream, ImageFormat.Png);
                result += Convert.ToBase64String(stream.GetBuffer());
            }
            else
            {
                throw new NotImplementedException();
            }

            w.WriteToken(JsonToken.String, result);
        }
开发者ID:lokeuei,项目名称:glTF,代码行数:28,代码来源:UriConverter.cs

示例7: WriteJson

        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var v8Item = value as V8ScriptItem;
            var jsType = v8Item.GetJsType();
            object outObj;
            if (jsType == JsTypes.jsError)
            {
                Dictionary<string, object> obj = new Dictionary<string, object>();
                obj["message"] = v8Item.GetProperty("message") as string;
                obj["stack"] = v8Item.GetProperty("stack") as string;
                foreach (var pname in v8Item.GetPropertyNames())
                {
                    var item = v8Item.GetProperty(pname);
                    if (ShouleSerialize(item, out outObj))
                    {
                        obj[pname] = outObj;
                    }

                }

                serializer.Serialize(writer, obj, obj.GetType());
            }
            else if (jsType == JsTypes.JsObject || jsType == JsTypes.JsArray || jsType == JsTypes.jsArguments)
            {

                try
                {
                    var json = v8Item.Engine.Script.JSON.stringify(v8Item);

                    if (writer is JTokenWriter)
                    {
                        var tw = new StringReader(json);
                        var jsonReader = new JsonTextReader(tw);

                        writer.WriteToken(jsonReader);

                    }
                    else
                    {
                        writer.WriteRaw(json);
                    }
                }
                catch (Exception)
                {

                    throw;
                }

            }
            else if (jsType == JsTypes.JsDate)
            {
                var dateString = (string)v8Item.InvokeMethod("toISOString", new object[0]);
                DateTime dt = DateTime.Parse(dateString, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.RoundtripKind);
                serializer.Serialize(writer, dt, dt.GetType());
            }
            else
            {
                writer.WriteNull();
            }
        }
开发者ID:dirkelfman,项目名称:ClearScript,代码行数:66,代码来源:IV8ScriptItem.cs


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