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


C# JToken.WriteTo方法代码示例

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


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

示例1: CompressJson

        byte[] CompressJson(JToken rpJsonToken)
        {
            using (var rMemoryStream = new MemoryStream())
            {
                using (var rCompressStream = new DeflateStream(rMemoryStream, CompressionMode.Compress))
                using (var rStreamWriter = new StreamWriter(rCompressStream))
                using (var rJsonTextWriter = new JsonTextWriter(rStreamWriter))
                    rpJsonToken.WriteTo(rJsonTextWriter);

                return rMemoryStream.ToArray();
            }
        }
开发者ID:amatukaze,项目名称:IntelligentNavalGun,代码行数:12,代码来源:BattleDetailRecords.cs

示例2: WriteValue

 protected static void WriteValue(JsonWriter writer, JToken value) {
     writer.WritePropertyName("value");
     value.WriteTo(writer);
 }
开发者ID:exceptionless,项目名称:Foundatio.Repositories,代码行数:4,代码来源:Operation.cs

示例3: SaveBlob

        static void SaveBlob(string storageConnectionString, string name, JToken content)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
            CloudBlobClient client = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = client.GetContainerReference("nuget");
            CloudBlockBlob blob = container.GetBlockBlobReference(name);

            blob.Properties.ContentType = "application/json";
            blob.Properties.CacheControl = "no-cache";

            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);
            using (JsonWriter jsonWriter = new JsonTextWriter(writer))
            {
                jsonWriter.Formatting = Formatting.Indented;

                content.WriteTo(jsonWriter);
                jsonWriter.Flush();
                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);
                blob.UploadFromStream(stream);
            }

            //Console.WriteLine(name);
        }
开发者ID:johnataylor,项目名称:render,代码行数:25,代码来源:Program.cs

示例4: SaveJTokenToTextFile

        public async Task<bool> SaveJTokenToTextFile(JToken token, string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                //throw new ArgumentNullException(nameof(fileName));
                return true;
            }
            try
            {
                // Write to file
                var path = fileName;
                if (!Path.IsPathRooted(path))
                {
                    //path = Path.Combine(Environment.CurrentDirectory, path);
                    path = PathHelper.Combine(Environment.CurrentDirectory, path);
                }
                //var dir = new DirectoryInfo(Path.GetDirectoryName(path));
                var dir = new DirectoryInfo(PathHelper.GetParent(path));
                if (!dir.Exists)
                    dir.Create();

                var exists = File.Exists(path);
                using (var stream = File.Open(path, exists ? FileMode.Truncate : FileMode.CreateNew, FileAccess.Write))
                {
                    var wr = new StreamWriter(stream);
                    var jw = new JsonTextWriter(wr)
                    {
                        Formatting = Formatting.Indented,
                    };
                    JsonConverter[] converters = new JsonConverter[0];
                    token.WriteTo(jw, converters);
                    await wr.FlushAsync();
                }
                System.Console.WriteLine("File saved: " + path);
                return true;
            }
            catch (Exception ex)
            {
                throw;
            }
            return false;
        }
开发者ID:LazyTarget,项目名称:FantasySimulator,代码行数:42,代码来源:FantasyPremierLeague2016DataFactory.cs

示例5: Write

		private void Write(JToken token)
		{
			if(token == null)
			{
				binaryWriter.Write((byte)JTokenType.Null);
				return;
			}
			binaryWriter.Write((byte)token.Type);
			switch (token.Type)
			{
				case JTokenType.None:
				case JTokenType.Constructor:
				case JTokenType.Comment:
				case JTokenType.Raw:
				case JTokenType.Property:
					throw new NotSupportedException("Can't write " + token);
				case JTokenType.Object:
				case JTokenType.Array:
					token.WriteTo(new BsonWriter(writer));
					break;
				case JTokenType.Integer:
					binaryWriter.Write(token.Value<int>());
					break;
				case JTokenType.Float:
					binaryWriter.Write(token.Value<float>());
					break;
				case JTokenType.String:
					binaryWriter.Write(token.Value<string>());
					break;
				case JTokenType.Boolean:
					binaryWriter.Write(token.Value<bool>());
					break;
				case JTokenType.Null:
				case JTokenType.Undefined:
					break;
				case JTokenType.Date:
					binaryWriter.Write(token.Value<DateTime>().ToBinary());
					break;
				case JTokenType.Bytes:
					var buffer = token.Value<byte[]>();
					binaryWriter.Write(buffer.Length);
					binaryWriter.Write(buffer);
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}
		}
开发者ID:jlundstocholm,项目名称:ravendb,代码行数:47,代码来源:Tree.cs

示例6: cb1

	public void cb1 (JToken obj, string graph_path, fbdump_params p)
	{
		if (obj.Type == JTokenType.Object) {
			JObject obj1 = (JObject)obj;
			string id = obj1 ["id"].Value<string> ();
			try {
				string fn = saveto + "/" + id;
				if (System.IO.File.Exists (fn))
					p.exists++;
				System.IO.FileStream fs = new System.IO.FileStream (fn, p.stop_on_existing ? FileMode.CreateNew : FileMode.Create);
				JsonWriter w = new JsonTextWriter (new StreamWriter (fs));
				obj.WriteTo (w);
				w.CloseOutput = true;
				w.Close ();
				if (graph_path != null) {
					string n = graph_path.Trim ('/').Replace ('/', '.');
					Mono.Unix.UnixSymbolicLinkInfo inf = new Mono.Unix.UnixSymbolicLinkInfo (saveto + "/" + n + "/" + id);
					inf.CreateSymbolicLinkTo ("../" + id);
				}
				foreach (JProperty pr in obj1.Properties()) {
					if (p.saveurl.Contains (pr.Name)) {
						saveurl (pr.Value.Value<string> (), id + "." + pr.Name);
					}
				}
			} catch (Exception ex) {
				Console.WriteLine (ex.Message);
				if (p.stop_on_existing) {
					stop ();
				}
			}
		}
	}
开发者ID:yodamaster,项目名称:workspace,代码行数:32,代码来源:MainWindow.cs


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