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


C# org.Opt方法代码示例

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


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

示例1: RowToString

		/// <summary>Produce a comma delimited text row from a JSONArray.</summary>
		/// <remarks>
		/// Produce a comma delimited text row from a JSONArray. Values containing
		/// the comma character will be quoted. Troublesome characters may be
		/// removed.
		/// </remarks>
		/// <param name="ja">A JSONArray of strings.</param>
		/// <returns>A string ending in NEWLINE.</returns>
		public static string RowToString(org.json.JSONArray ja)
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			for (int i = 0; i < ja.Length(); i += 1)
			{
				if (i > 0)
				{
					sb.Append(',');
				}
				object @object = ja.Opt(i);
				if (@object != null)
				{
					string @string = @object.ToString();
					if (@string.Length > 0 && (@string.IndexOf(',') >= 0 || @string.IndexOf('\n') >= 0 || @string.IndexOf('\r') >= 0 || @string.IndexOf(0) >= 0 || @string[0] == '"'))
					{
						sb.Append('"');
						int length = @string.Length;
						for (int j = 0; j < length; j += 1)
						{
							char c = @string[j];
							if (c >= ' ' && c != '"')
							{
								sb.Append(c);
							}
						}
						sb.Append('"');
					}
					else
					{
						sb.Append(@string);
					}
				}
			}
			sb.Append('\n');
			return sb.ToString();
		}
开发者ID:davidraleigh,项目名称:geometry-api-cs-tests,代码行数:44,代码来源:CDL.cs

示例2: ToString

		/// <summary>Reverse the JSONML transformation, making an XML text from a JSONArray.</summary>
		/// <param name="ja">A JSONArray.</param>
		/// <returns>An XML string.</returns>
		/// <exception cref="JSONException"/>
		/// <exception cref="org.json.JSONException"/>
		public static string ToString(org.json.JSONArray ja)
		{
			int i;
			org.json.JSONObject jo;
			string key;
			System.Collections.Generic.IEnumerator<string> keys;
			int length;
			object @object;
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			string tagName;
			string value;
			// Emit <tagName
			tagName = ja.GetString(0);
			org.json.XML.NoSpace(tagName);
			tagName = org.json.XML.Escape(tagName);
			sb.Append('<');
			sb.Append(tagName);
			@object = ja.Opt(1);
			if (@object is org.json.JSONObject)
			{
				i = 2;
				jo = (org.json.JSONObject)@object;
				// Emit the attributes
				keys = jo.Keys();
				while (keys.HasNext())
				{
					key = keys.Next();
					org.json.XML.NoSpace(key);
					value = jo.OptString(key);
					if (value != null)
					{
						sb.Append(' ');
						sb.Append(org.json.XML.Escape(key));
						sb.Append('=');
						sb.Append('"');
						sb.Append(org.json.XML.Escape(value));
						sb.Append('"');
					}
				}
			}
			else
			{
				i = 1;
			}
			// Emit content in body
			length = ja.Length();
			if (i >= length)
			{
				sb.Append('/');
				sb.Append('>');
			}
			else
			{
				sb.Append('>');
				do
				{
					@object = ja.Get(i);
					i += 1;
					if (@object != null)
					{
						if (@object is string)
						{
							sb.Append(org.json.XML.Escape(@object.ToString()));
						}
						else
						{
							if (@object is org.json.JSONObject)
							{
								sb.Append(ToString((org.json.JSONObject)@object));
							}
							else
							{
								if (@object is org.json.JSONArray)
								{
									sb.Append(ToString((org.json.JSONArray)@object));
								}
								else
								{
									sb.Append(@object.ToString());
								}
							}
						}
					}
				}
				while (i < length);
				sb.Append('<');
				sb.Append('/');
				sb.Append(tagName);
				sb.Append('>');
			}
			return sb.ToString();
		}
开发者ID:davidraleigh,项目名称:geometry-api-cs-tests,代码行数:97,代码来源:JSONML.cs

示例3: JSONObject

		/// <summary>Construct a JSONObject from a subset of another JSONObject.</summary>
		/// <remarks>
		/// Construct a JSONObject from a subset of another JSONObject. An array of
		/// strings is used to identify the keys that should be copied. Missing keys
		/// are ignored.
		/// </remarks>
		/// <param name="jo">A JSONObject.</param>
		/// <param name="names">An array of strings.</param>
		/// <exception cref="JSONException"/>
		/// <exception>
		/// JSONException
		/// If a value is a non-finite number or if a name is
		/// duplicated.
		/// </exception>
		public JSONObject(org.json.JSONObject jo, string[] names)
			: this()
		{
			for (int i = 0; i < names.Length; i += 1)
			{
				try
				{
					this.PutOnce(names[i], jo.Opt(names[i]));
				}
				catch (System.Exception)
				{
				}
			}
		}
开发者ID:davidraleigh,项目名称:geometry-api-cs-tests,代码行数:28,代码来源:JSONObject.cs


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