本文整理汇总了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();
}
示例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();
}
示例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)
{
}
}
}