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


C# JArray.WriteTo方法代码示例

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


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

示例1: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            JArray array = new JArray();
            IList list = (IList)value;
            if (list.Count > 0)
            {
                JArray keys = new JArray();

                JObject first = JObject.FromObject(list[0], serializer);
                foreach (JProperty prop in first.Properties())
                {
                    keys.Add(new JValue(prop.Name));
                }
                array.Add(keys);

                foreach (object item in list)
                {
                    JObject obj = JObject.FromObject(item, serializer);
                    JArray itemValues = new JArray();
                    foreach (JProperty prop in obj.Properties())
                    {
                        itemValues.Add(prop.Value);
                    }
                    array.Add(itemValues);
                }
            }
            array.WriteTo(writer);
        }
开发者ID:Kaliido,项目名称:QuickBloxDotNetRestApi,代码行数:28,代码来源:ListCompactionConverter.cs

示例2: WriteJson

    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
      ConverterPrecedenceClass c = (ConverterPrecedenceClass)value;

      JToken j = new JArray(ConverterType, c.TestValue);

      j.WriteTo(writer);
    }
开发者ID:284247028,项目名称:MvvmCross,代码行数:8,代码来源:ConverterPrecedenceClassConverter.cs

示例3: TryReplicatingData

 private bool TryReplicatingData(string destination, JArray jsonDocuments)
 {
     try
     {
         var request = (HttpWebRequest)WebRequest.Create(destination + "/replication/replicate?from=" + docDb.Configuration.ServerUrl);
         request.UseDefaultCredentials = true;
         request.Credentials = CredentialCache.DefaultNetworkCredentials;
         request.Method = "POST";
         using (var stream = request.GetRequestStream())
         using (var streamWriter = new StreamWriter(stream))
         {
             jsonDocuments.WriteTo(new JsonTextWriter(streamWriter));
             streamWriter.Flush();
             stream.Flush();
         }
         using (request.GetResponse())
         {
             log.InfoFormat("Replicated {0} to {1}", jsonDocuments.Count, destination);
         }
         return true;
     }
     catch (WebException e)
     {
         var response = e.Response as HttpWebResponse;
         if (response != null)
         {
             using (var streamReader = new StreamReader(response.GetResponseStream()))
             {
                 var error = streamReader.ReadToEnd();
                 log.Warn("Replication to " + destination + " had failed\r\n" + error, e);
             }
         }
         else
         {
             log.Warn("Replication to " + destination + " had failed", e);
         }
         return false;
     }
     catch (Exception e)
     {
         log.Warn("Replication to " + destination + " had failed", e);
         return false;
     }
 }
开发者ID:Rationalle,项目名称:ravendb,代码行数:44,代码来源:ReplicationTask.cs

示例4: FlushBatch

        private static void FlushBatch(string instanceUrl, List<JObject> batch)
        {
        	var sw = Stopwatch.StartNew();
        	long size;
            using (var webClient = new WebClient())
            {
				webClient.Headers.Add("Content-Type", "application/json; charset=utf-8");
				webClient.UseDefaultCredentials = true;
                webClient.Credentials = CredentialCache.DefaultNetworkCredentials;
				using (var stream = new MemoryStream())
				{
					using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
					using (var jsonTextWriter = new JsonTextWriter(streamWriter))
					{
						var commands = new JArray();
						foreach (var doc in batch)
						{
							var metadata = doc.Value<JObject>("@metadata");
							doc.Remove("@metadata");
							commands.Add(new JObject(
											 new JProperty("Method", "PUT"),
											 new JProperty("Document", doc),
											 new JProperty("Metadata", metadata),
											 new JProperty("Key", metadata.Value<string>("@id"))
											 ));
						}
						commands.WriteTo(jsonTextWriter);
						jsonTextWriter.Flush();
						streamWriter.Flush();
						stream.Flush();
						size = stream.Length;

						using (var netStream = webClient.OpenWrite(instanceUrl + "bulk_docs", "POST"))
						{
							stream.WriteTo(netStream);
							netStream.Flush();
						}
					}
				}
                
            }
        	Console.WriteLine("Wrote {0} documents [{1:#,#} kb] in {2:#,#} ms",
        	                  batch.Count, Math.Round((double)size/1024, 2), sw.ElapsedMilliseconds);
            batch.Clear();
        }
开发者ID:ajaishankar,项目名称:ravendb,代码行数:45,代码来源:Smuggler.cs

示例5: TryReplicationDocuments

        private bool TryReplicationDocuments(string destination, JArray jsonDocuments)
        {
            try
            {
            	log.DebugFormat("Starting to replicate {0} documents to {1}", jsonDocuments.Count, destination);
				var request = (HttpWebRequest)WebRequest.Create(destination + "/replication/replicateDocs?from=" + UrlEncodedServerUrl());
                request.UseDefaultCredentials = true;
            	request.ContentType = "application/json; charset=utf-8";
                request.Credentials = CredentialCache.DefaultNetworkCredentials;
                request.Method = "POST";
                using (var stream = request.GetRequestStream())
                using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
                {
                    jsonDocuments.WriteTo(new JsonTextWriter(streamWriter));
                    streamWriter.Flush();
                    stream.Flush();
                }
                using (request.GetResponse())
                {
                    log.InfoFormat("Replicated {0} documents to {1}", jsonDocuments.Count, destination);
                }
                return true;
            }
            catch (WebException e)
            {
                var response = e.Response as HttpWebResponse;
                if (response != null)
                {
                    using (var streamReader = new StreamReader(response.GetResponseStream()))
                    {
                        var error = streamReader.ReadToEnd();
                        log.Warn("Replication to " + destination + " had failed\r\n" + error, e);
                    }
                }
                else
                {
                    log.Warn("Replication to " + destination + " had failed", e);
                }
                return false;
            }
            catch (Exception e)
            {
                log.Warn("Replication to " + destination + " had failed", e);
                return false;
            }
        }
开发者ID:philiphoy,项目名称:ravendb,代码行数:46,代码来源:ReplicationTask.cs

示例6: FlushBatch

 private static void FlushBatch(string instanceUrl, List<JObject> batch)
 {
     using (var webClient = new WebClient())
     {
         webClient.UseDefaultCredentials = true;
         webClient.Credentials = CredentialCache.DefaultNetworkCredentials;
         using (var stream = webClient.OpenWrite(instanceUrl + "bulk_docs", "POST"))
         using (var streamWriter = new StreamWriter(stream))
         using (var jsonTextWriter = new JsonTextWriter(streamWriter))
         {
             var commands = new JArray();
             foreach (var doc in batch)
             {
                 var metadata = doc.Value<JObject>("@metadata");
                 doc.Remove("@metadata");
                 commands.Add(new JObject(
                                  new JProperty("Method", "PUT"),
                                  new JProperty("Document", doc),
                                  new JProperty("Metadata", metadata),
                                  new JProperty("Key", metadata.Value<string>("@id"))
                                  ));
             }
             commands.WriteTo(jsonTextWriter);
             jsonTextWriter.Flush();
             streamWriter.Flush();
         }
     }
     batch.Clear();
 }
开发者ID:kenegozi,项目名称:ravendb,代码行数:29,代码来源:Smuggler.cs

示例7: WriteCommands

        private static void WriteCommands(IEnumerable<Command> cmds, Stream log)
        {
            var array = new JArray();
            foreach (var command in cmds)
            {
                var cmd = new JObject
                {
                    {"type", (byte) command.Type},
                    {"key", command.Key},
                    {"dicId", command.DictionaryId}
                };

                if (command.Type == CommandType.Put)
                {
                    cmd.Add("position", command.Position);
                    cmd.Add("size", command.Size);
                }

                array.Add(cmd);
            }

            array.WriteTo(new BsonWriter(log));
        }
开发者ID:ayende,项目名称:Degenerated.Storage,代码行数:23,代码来源:AggregateDictionary.cs


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