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