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


C# JsonTextWriter.WriteStartObject方法代码示例

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


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

示例1: DeleteFromIndex

        public override bool DeleteFromIndex(ISearchableItem item)
        {
            Initialise();

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            using (JsonTextWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.Indented;

                writer.WriteStartObject();
                writer.WritePropertyName("delete");
                writer.WriteStartObject();

                writer.WritePropertyName("id");
                writer.WriteValue(item.ItemKey.TypeId.ToString() + "," + item.Id.ToString());

                writer.WriteEndObject();
                writer.WriteEndObject();
            }

            try
            {
                WebClient wc = new WebClient();
                wc.Headers[HttpRequestHeader.ContentType] = "type:application/json";
                wc.UploadString("http://" + server + "/update/json", sb.ToString());
                wc.DownloadString("http://" + server + "/update?commit=true");
            }
            catch
            {
            }

            return true;
        }
开发者ID:smithydll,项目名称:boxsocial,代码行数:35,代码来源:SolrSearch.cs

示例2: Serialize

        public string Serialize()
        {
            var sb = new StringBuilder();
            var sw = new StringWriter(sb);

            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = Formatting.Indented;

                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyName("public");
                jsonWriter.WriteValue(true);

                jsonWriter.WritePropertyName("files");

                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyName(File);

                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyName("content");
                jsonWriter.WriteValue(Code);
                jsonWriter.WriteEndObject();

                jsonWriter.WriteEndObject();

                jsonWriter.WriteEndObject();
            }

            return sb.ToString();
        }
开发者ID:perikete,项目名称:SendToGist,代码行数:30,代码来源:GistPublishRequest.cs

示例3: ToJSONRepresentation

        public String ToJSONRepresentation()
        {
            StringBuilder sb = new StringBuilder();
            JsonWriter jw = new JsonTextWriter(new StringWriter(sb));

            jw.Formatting = Formatting.Indented;
            jw.WriteStartObject();
            jw.WritePropertyName(this._description);
            jw.WriteStartArray();

            foreach(MailStructure mail in this._mailStructures)
            {
                jw.WriteStartObject();
                jw.WritePropertyName("Id");
                jw.WriteValue(mail.Id);
                jw.WritePropertyName("Uuid");
                jw.WriteValue(mail.Uuid);
                jw.WritePropertyName("MailDate");
                jw.WriteValue(mail.MailDate);
                jw.WritePropertyName("From");
                jw.WriteValue(mail.From);
                jw.WritePropertyName("Subject");
                jw.WriteValue(mail.Subject);
                jw.WritePropertyName("Body");
                jw.WriteValue(mail.Body);
                jw.WritePropertyName("AttachmentExist");
                jw.WriteValue((mail.AttachmentExist ? "1" : "0"));
                jw.WritePropertyName("AttachmentFiles");
                jw.WriteValue(mail.AttachmentFiles);
                jw.WriteEndObject();
            }
            jw.WriteEndArray();
            jw.WriteEndObject();
            return sb.ToString();
        }
开发者ID:shestakovg,项目名称:mail1c,代码行数:35,代码来源:MailJsonSerializer.cs

示例4: ToJson

 /// <summary>
 /// Serializes <see cref="Graphic"/> into JSON string.
 /// </summary>
 /// <param name="graphic">graphic to serialize into JSON.</param>
 /// <returns>string representation of the JSON object.</returns>
 public static string ToJson(this  Graphic graphic)
 {
     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
     {
         using (JsonWriter jw = new JsonTextWriter(sw))
         {
             if (graphic.Geometry != null)
             {
                 jw.WriteStartObject();
                 jw.WritePropertyName("geometry");
                 // Gets the JSON string representation of the Geometry.
                 jw.WriteRawValue(graphic.Geometry.ToJson());
                 jw.WriteEndObject();
             }
             if (graphic.Attributes.Count > 0)
             {
                 jw.WriteStartObject();
                 foreach (var item in graphic.Attributes)
                 {
                     jw.WritePropertyName(item.Key);
                     jw.WriteValue(item.Value);
                 }
                 jw.WriteEndObject();
             }
         }
         return sb.ToString();
     }
 }
开发者ID:jNery,项目名称:geoenrichment_wp8,代码行数:34,代码来源:GraphicExtension.cs

示例5: ToJsonString

        /// <summary>
        /// Serialize this phase to JSON.
        /// </summary>
        /// <returns>The phase as a JSON string.</returns>
        public string ToJsonString()
        {
            /*
             * NB: JsonTextWriter is guaranteed to close the StringWriter
             * https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/JsonTextWriter.cs#L150-L160
             */
            var sb = new StringBuilder();
            var sw = new StringWriter(sb);
            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.WriteStartObject();
                writer.WritePropertyName(PhaseType);

                // phase start
                writer.WriteStartObject();

                WriteJson(writer);
                writer.WriteProperty("keep", keep);
                writer.WriteEndObject();

                // phase end
                writer.WriteEndObject();
            }

            return sb.ToString();
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:30,代码来源:RiakPhase.cs

示例6: MapFromAttributes

        internal string MapFromAttributes()
        {
            var sb = new StringBuilder();
            using (StringWriter sw = new StringWriter(sb))
            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = Formatting.Indented;
                jsonWriter.WriteStartObject();
                {
                    var typeName = this.TypeName.Resolve(this._connectionSettings);
                    jsonWriter.WritePropertyName(typeName);
                    jsonWriter.WriteStartObject();
                    {
                        this.WriteRootObjectProperties(jsonWriter);

                        jsonWriter.WritePropertyName("properties");
                        jsonWriter.WriteStartObject();
                        {
                            this.WriteProperties(jsonWriter);
                        }
                        jsonWriter.WriteEnd();
                    }
                    jsonWriter.WriteEnd();
                }
                jsonWriter.WriteEndObject();

                return sw.ToString();
            }
        }
开发者ID:Rustemt,项目名称:NEST,代码行数:29,代码来源:TypeMappingWriter.cs

示例7: DataTableToJSON

    public static string DataTableToJSON(DataTable dt, string dtName)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);

        using (JsonWriter jw = new JsonTextWriter(sw))
        {
            JsonSerializer ser = new JsonSerializer();
            jw.WriteStartObject();
            jw.WritePropertyName(dtName);
            jw.WriteStartArray();
            foreach (DataRow dr in dt.Rows)
            {
                jw.WriteStartObject();

                foreach (DataColumn dc in dt.Columns)
                {
                    jw.WritePropertyName(dc.ColumnName);
                    ser.Serialize(jw, dr[dc].ToString());
                }

                jw.WriteEndObject();
            }
            jw.WriteEndArray();
            jw.WriteEndObject();

            sw.Close();
            jw.Close();

        }

        return sb.ToString();
    }
开发者ID:ichari,项目名称:ichari,代码行数:33,代码来源:JsonHelper.cs

示例8: CreateStatusText

	private string CreateStatusText()
	{
		using (var sw = new StringWriter())
		using (var jsonWriter = new JsonTextWriter(sw))
		{
			jsonWriter.WriteStartObject();
			{
				// Login
				jsonWriter.WritePropertyName("login");
				jsonWriter.WriteStartObject();
				{
					jsonWriter.WritePropertyName("port");
					jsonWriter.WriteValue(LoginServer.Instance.Conf.Login.Port);
				}
				jsonWriter.WriteEndObject();

				// Servers
				jsonWriter.WritePropertyName("servers");
				jsonWriter.WriteStartObject();
				{
					foreach (var server in LoginServer.Instance.ServerList.List)
					{
						// Channels
						jsonWriter.WritePropertyName(server.Name);
						jsonWriter.WriteStartObject();
						{
							foreach (var channel in server.Channels)
							{
								// Channel
								jsonWriter.WritePropertyName(channel.Key);
								jsonWriter.WriteStartObject();
								{
									jsonWriter.WritePropertyName("host");
									jsonWriter.WriteValue(channel.Value.Host);

									jsonWriter.WritePropertyName("port");
									jsonWriter.WriteValue(channel.Value.Port);

									jsonWriter.WritePropertyName("online");
									jsonWriter.WriteValue(channel.Value.Users);

									jsonWriter.WritePropertyName("onlineMax");
									jsonWriter.WriteValue(channel.Value.MaxUsers);

									jsonWriter.WritePropertyName("state");
									jsonWriter.WriteValue(channel.Value.State);
								}
								jsonWriter.WriteEndObject();
							}
						}
						jsonWriter.WriteEndObject();
					}
				}
				jsonWriter.WriteEndObject();
			}
			jsonWriter.WriteEndObject();

			return sw.ToString();
		}
	}
开发者ID:aura-project,项目名称:aura,代码行数:60,代码来源:status.cs

示例9: GenerateJson

        /// <summary>
        /// Generate the json output for the page.
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string GenerateJson(IContent page)
        {
            string json;

            List<KeyValuePair<string, string>> propertyValues = page.GetPropertyValues();

            StringBuilder stringBuilder = new StringBuilder();

            using (StringWriter sw = new StringWriter(stringBuilder, CultureInfo.InvariantCulture))
            {
                JsonWriter jsonWriter = new JsonTextWriter(sw) { Formatting = Formatting.Indented };

                jsonWriter.WriteStartObject();

                jsonWriter.WritePropertyName(page.Name);

                jsonWriter.WriteStartObject();

                foreach (KeyValuePair<string, string> content in propertyValues)
                {
                    jsonWriter.WritePropertyName(content.Key);
                    jsonWriter.WriteValue(TextIndexer.StripHtml(content.Value, content.Value.Length));
                }

                jsonWriter.WriteEndObject();

                jsonWriter.WriteEndObject();

                json = sw.ToString();
            }

            return json;
        }
开发者ID:jstemerdink,项目名称:EPiServer.Libraries,代码行数:42,代码来源:JsonOutputFormat.cs

示例10: parameterFieldMapJson

        /// <summary>
        /// Convert parameter list to json object
        /// </summary>
        public static string parameterFieldMapJson(parameters parms, string ProjectID, string QueryID)
        {
            StringWriter sw = new StringWriter();
            JsonTextWriter json = new JsonTextWriter(sw);

            json.WriteStartObject();
            json.WritePropertyName("results");
            json.WriteStartArray();
            json.WriteStartObject();
            // ProjectID and QueryID
            json.WritePropertyName("ProjectID");
            json.WriteValue(ProjectID);
            json.WritePropertyName("QueryID");
            json.WriteValue(QueryID);

            json.WritePropertyName("parameters");
            json.WriteRawValue(JsonConvert.SerializeObject(parms));

            json.WriteEndObject();
            json.WriteEndArray();
            json.WriteEndObject();

            json.Flush();
            sw.Flush();

            return sw.ToString();
        }
开发者ID:kstubs,项目名称:ProjFlx,代码行数:30,代码来源:Helper.cs

示例11: WriteAsJson

        public static void WriteAsJson([NotNull] this LayoutBuilder layoutBuilder, [NotNull] TextWriter writer)
        {
            var output = new JsonTextWriter(writer)
            {
                Formatting = Formatting.Indented
            };

            output.WriteStartObject("Layout");
            output.WriteStartArray("Devices");

            foreach (var deviceBuilder in layoutBuilder.Devices)
            {
                output.WriteStartObject();
                output.WritePropertyStringIf("Name", deviceBuilder.DeviceName);
                output.WritePropertyStringIf("Layout", deviceBuilder.LayoutItemPath);

                output.WriteStartArray("Renderings");

                foreach (var renderingBuilder in deviceBuilder.Renderings.Where(r => r.ParentRendering == null))
                {
                    WriteAsJson(output, deviceBuilder, renderingBuilder);
                }

                output.WriteEndArray();
                output.WriteEndObject();
            }

            output.WriteEndArray();
            output.WriteEndObject();
        }
开发者ID:pveller,项目名称:Sitecore.Pathfinder,代码行数:30,代码来源:FormatExtensions.cs

示例12: WriteTransaction

		protected override void WriteTransaction(JsonTextWriter writer, Transaction tx)
		{
			WritePropertyValue(writer, "hash", tx.GetHash().ToString());
			WritePropertyValue(writer, "ver", tx.Version);

			WritePropertyValue(writer, "vin_sz", tx.Inputs.Count);
			WritePropertyValue(writer, "vout_sz", tx.Outputs.Count);

			WritePropertyValue(writer, "lock_time", tx.LockTime.Value);

			WritePropertyValue(writer, "size", tx.GetSerializedSize());

			writer.WritePropertyName("in");
			writer.WriteStartArray();
			foreach(var input in tx.Inputs.AsIndexedInputs())
			{
				var txin = input.TxIn;
				writer.WriteStartObject();
				writer.WritePropertyName("prev_out");
				writer.WriteStartObject();
				WritePropertyValue(writer, "hash", txin.PrevOut.Hash.ToString());
				WritePropertyValue(writer, "n", txin.PrevOut.N);
				writer.WriteEndObject();

				if(txin.PrevOut.Hash == uint256.Zero)
				{
					WritePropertyValue(writer, "coinbase", Encoders.Hex.EncodeData(txin.ScriptSig.ToBytes()));
				}
				else
				{
					WritePropertyValue(writer, "scriptSig", txin.ScriptSig.ToString());
				}
				if(input.WitScript != WitScript.Empty)
				{
					WritePropertyValue(writer, "witness", input.WitScript.ToString());
				}
				if(txin.Sequence != uint.MaxValue)
				{
					WritePropertyValue(writer, "sequence", (uint)txin.Sequence);
				}
				writer.WriteEndObject();
			}
			writer.WriteEndArray();
			writer.WritePropertyName("out");
			writer.WriteStartArray();
			
			foreach(var txout in tx.Outputs)
			{
				writer.WriteStartObject();
				WritePropertyValue(writer, "value", txout.Value.ToString(false, false));
				WritePropertyValue(writer, "scriptPubKey", txout.ScriptPubKey.ToString());
				writer.WriteEndObject();
			}
			writer.WriteEndArray();
		}
开发者ID:knocte,项目名称:NBitcoin,代码行数:55,代码来源:BlockExplorerFormatter.cs

示例13: Go

        private static void Go(Engine engine)
        {
            var missionDefinitionClass = engine.GetClass("WillowGame.MissionDefinition");
            if (missionDefinitionClass == null)
            {
                throw new InvalidOperationException();
            }

            using (var output = new StreamWriter("Missions.json", false, Encoding.Unicode))
            using (var writer = new JsonTextWriter(output))
            {
                writer.Indentation = 2;
                writer.IndentChar = ' ';
                writer.Formatting = Formatting.Indented;

                writer.WriteStartObject();

                var missionDefinitions = engine.Objects
                    .Where(o => o.IsA(missionDefinitionClass) &&
                                o.GetName().StartsWith("Default__") ==
                                false)
                    .OrderBy(o => o.GetPath());
                foreach (dynamic missionDefinition in missionDefinitions)
                {
                    writer.WritePropertyName(missionDefinition.GetPath());
                    writer.WriteStartObject();

                    writer.WritePropertyName("number");
                    writer.WriteValue(missionDefinition.MissionNumber);

                    string missionName = missionDefinition.MissionName;
                    if (string.IsNullOrEmpty(missionName) == false)
                    {
                        writer.WritePropertyName("name");
                        writer.WriteValue(missionName);
                    }

                    string missionDescription = missionDefinition.MissionDescription;
                    if (string.IsNullOrEmpty(missionDescription) == false)
                    {
                        writer.WritePropertyName("description");
                        writer.WriteValue(missionDescription);
                    }

                    // TODO: objective info

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
                writer.Flush();
            }
        }
开发者ID:spitfire1337,项目名称:Borderlands-2-Save-Editor,代码行数:53,代码来源:Program.cs

示例14: Start

        public bool Start(string context)
        {
            this.context = context;
            string uri = baseURI + @"start/";
            string method = "POST";
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
 
            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = Formatting.Indented;
 
                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyName("context");
                jsonWriter.WriteValue(this.context);
                jsonWriter.WritePropertyName("participants");
                jsonWriter.WriteStartArray();
                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyName("name");
                // use the current window user
                jsonWriter.WriteValue(Environment.UserName);
                jsonWriter.WritePropertyName("id");
                // use the computer name + windows user name
                jsonWriter.WriteValue(Environment.MachineName + "-" + Environment.UserName);
                jsonWriter.WriteEndObject();
                jsonWriter.WriteEnd();
                jsonWriter.WriteEndObject();
            }
            string json = sb.ToString();
            
            HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
            req.KeepAlive = false;
            req.Method = method;
            byte[] buffer = Encoding.ASCII.GetBytes(json);
            req.ContentLength = buffer.Length;
            req.ContentType = "application/json";
            Stream PostData = req.GetRequestStream();
            PostData.Write(buffer, 0, buffer.Length);
            PostData.Close();

            HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
            StreamReader tr = new StreamReader(resp.GetResponseStream());
            json = tr.ReadToEnd();            
            Dictionary<string, string> respValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
            if (respValues.ContainsKey("status") && respValues["status"] == "success")
            {
                this.dialogueID = respValues["dlg_id"];
                this.IsRunning = true;
                return true;
            }
            return false;
        }
开发者ID:cdbean,项目名称:CAGA,代码行数:52,代码来源:DialogueAgent.cs

示例15: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();

             var oSB = new StringBuilder();
             var oSW = new StringWriter(oSB);

             using (JsonWriter oWriter = new JsonTextWriter(oSW))
             {
            oWriter.Formatting = Formatting.Indented;

            oWriter.WriteStartObject();

            if (IsAuthenticated && ApplicationContext.IsStaff)
            {
               oWriter.WritePropertyName("results");
               oWriter.WriteStartArray();

               if (!string.IsNullOrEmpty(Request.QueryString["q"]))
               {
                  var sQuery = Request.QueryString["q"];
                  DataAccess.Log = new DebugTextWriter();

                  var oResults = DataAccess.fn_Producer_GetCustomerLookup();
                  oResults = oResults.Where(row => (row.FirstName + " " + row.LastName + " (" + row.Username + ")").Contains(sQuery))
                                     .Distinct().Take(30);

                  foreach (var oResult in oResults)
                  {
                     oWriter.WriteStartObject();
                     oWriter.WritePropertyName("id");
                     oWriter.WriteValue(oResult.MPUserID.ToString());
                     oWriter.WritePropertyName("name");
                     oWriter.WriteValue(string.Format("{0} {1} ({2})", oResult.FirstName, oResult.LastName, oResult.Username));
                     oWriter.WriteEndObject();
                  }

                  oWriter.WriteEnd();
               }
            }

            oWriter.WriteEndObject();
             }

             Response.ContentType = "application/json";
             Response.Write(oSB.ToString());
             Response.End();
        }
开发者ID:psychotiic,项目名称:speedyspots,代码行数:48,代码来源:ajax-customer-lookup.aspx.cs


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