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