本文整理了Java中com.atlassian.jira.util.json.JSONArray
类的一些代码示例,展示了JSONArray
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray
类的具体详情如下:
包路径:com.atlassian.jira.util.json.JSONArray
类名称:JSONArray
[英]A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with commas separating the values. The internal form is an object having get
and opt
methods for accessing the values by index, and put
methods for adding or replacing values. The values can be any of these types: Boolean
, JSONArray
, JSONObject
, Number
, String
, or the JSONObject.NULL object
.
The constructor can convert a JSON text into a Java object. The toString
method converts to JSON text.
A get
method returns a value if one can be found, and throws an exception if one cannot be found. An opt
method returns a default value instead of throwing an exception, and so is useful for obtaining optional values.
The generic get()
and opt()
methods return an object which you can cast or query for type. There are also typed get
and opt
methods that do type checking and type coersion for you.
The texts produced by the toString
methods strictly conform to JSON syntax rules. The constructors are more forgiving in the texts they will accept:
,
(comma) may appear just before the closing bracket.null
value will be inserted when there is ,
(comma) elision.'
(single quote).{ } [ ] / \ : , = ; #
and if they do not look like numbers and if they are not the reserved words true
, false
, or null
.;
(semicolon) as well as by ,
(comma).0-
(octal) or 0x-
(hex) prefix.get
和opt
方法用于按索引访问值,以及put
方法用于添加或替换值。这些值可以是以下任何类型:Boolean
、JSONArray
、JSONObject
、Number
、String
或JSONObject.NULL object
。toString
方法将转换为JSON文本。get
方法,则返回一个值;如果找不到,则抛出一个异常。opt
方法返回默认值而不是引发异常,因此对于获取可选值非常有用。get()
和opt()
方法返回一个对象,您可以强制转换或查询该对象的类型。还有类型化的get
和opt
方法可以为您进行类型检查和类型协同。toString
方法生成的文本严格遵守JSON语法规则。构造器在他们将接受的文本中更加宽容:,
(逗号)。,
(逗号)省略时,将插入null
值。'
引用(单引号)。true
、false
或null
,则根本不需要引用字符串。;
(分号)和,
(逗号)分隔。0-
(八进制)或0x-
(十六进制)前缀。代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Convert the passed array into SharePermissions.
*
* @param array the JSON array to convert.
* @return the converted SharePermission.
* @throws JSONException if an error occurs during convertion.
*/
public static SharePermissions fromJsonArray(final JSONArray array) throws JSONException
{
notNull("array", array);
final Set<SharePermission> permissions = new HashSet<SharePermission>(array.length());
for (int i = 0; i < array.length(); i++)
{
permissions.add(SharePermissionUtils.fromJsonObject(array.getJSONObject(i)));
}
return new SharePermissions(permissions);
}
代码示例来源:origin: com.atlassian.jira/jira-core
public String getJqlReservedWordsJson() throws JSONException
{
final Set<String> reservedWords = jqlStringSupport.getJqlReservedWords();
JSONArray results = new JSONArray();
for (String reservedWord : reservedWords)
{
results.put(reservedWord);
}
return results.toString();
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Produce a JSONArray containing the values of the members of this
* JSONObject.
*
* @param names A JSONArray containing a list of key strings. This
* determines the sequence of the values in the result.
* @return A JSONArray of values.
* @throws JSONException If any of the values are non-finite numbers.
*/
public JSONArray toJSONArray(final JSONArray names) throws JSONException
{
if ((names == null) || (names.length() == 0))
{
return null;
}
final JSONArray ja = new JSONArray();
for (int i = 0; i < names.length(); i += 1)
{
ja.put(opt(names.getString(i)));
}
return ja;
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Put a value in the JSONArray, where the value will be a
* JSONArray which is produced from a Collection.
*
* @param value A Collection value.
* @return this.
*/
public JSONArray put(final Collection<Object> value)
{
put(new JSONArray(value));
return this;
}
代码示例来源:origin: com.atlassian.jira/jira-api
private static Collection<String> getGroups(final JSONArray jsonArray) throws JSONException
{
Set<String> groups = Sets.newHashSetWithExpectedSize(jsonArray.length());
for (int i = 0 ; i<jsonArray.length(); i++)
{
groups.add(jsonArray.getString(i));
}
return groups;
}
代码示例来源:origin: com.atlassian.jira/jira-api
private static Collection<Long> getRoleIds(final JSONArray jsonArray) throws JSONException
{
Set<Long> roleIds = Sets.newHashSetWithExpectedSize(jsonArray.length());
for (int i = 0 ; i<jsonArray.length(); i++)
{
roleIds.add(jsonArray.getLong(i));
}
return roleIds;
}
代码示例来源:origin: com.atlassian.jira/jira-core
private Collection<RemoteProject> parseProjects(final String response, final ApplicationLink applicationLink)
throws ResponseException, CredentialsRequiredException
{
try
{
JSONArray json = new JSONArray(response);
int length = json.length();
final Collection<RemoteProject> projects = new ArrayList<RemoteProject>(length);
for (int i = 0; i < length; i++)
{
projects.add(RemoteProject.from(applicationLink, json.getJSONObject(i)));
}
return projects;
}
catch (JSONException ex)
{
throw new RuntimeException("Unable to parse the JSON response for get projects : " + response, ex);
}
}
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Produce a JSONArray containing the names of the elements of this
* JSONObject.
*
* @return A JSONArray containing the key strings, or null if the JSONObject
* is empty.
*/
public JSONArray names()
{
final JSONArray ja = new JSONArray();
for (final String key : keySet())
{
ja.put(key);
}
return ja.length() == 0 ? null : ja;
}
代码示例来源:origin: com.atlassian.jira/jira-core
private static List<String> parseShortcut(String shortcut) throws JSONException
{
if (JSON_VALUE_ARRAY.matcher(shortcut).matches())
{
final JSONArray array = new JSONArray(shortcut);
final List<String> result = Lists.newArrayListWithCapacity(array.length());
for (int i = 0; i < array.length(); i++) {
result.add(array.getString(i));
}
return result;
}
else if (JSON_VALUE_STRING.matcher(shortcut).matches())
{
final String key = "shortcut";
JSONObject json = new JSONObject(String.format("{ \"%s\": %s }", key, shortcut));
return Arrays.asList(json.getString(key));
}
else
{
final List<String> result = new ArrayList<String>();
for (char c : shortcut.toCharArray())
{
result.add(String.valueOf(c));
}
return result;
}
}
代码示例来源:origin: com.atlassian.jira.plugins/jira-healthcheck-plugin
@Override
public String failureReason()
{
if (failureReasons.isEmpty())
{
return null;
}
if (failureReasons.size() == 1)
{
return failureReasons.get(0);
}
return new JSONArray(failureReasons).toString();
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Produce a JSONObject by combining a JSONArray of names with the values
* of this JSONArray.
*
* @param names A JSONArray containing a list of key strings. These will be
* paired with the values.
* @return A JSONObject, or null if there are no names or if this JSONArray
* has no values.
* @throws JSONException If any of the names are null.
*/
public JSONObject toJSONObject(final JSONArray names) throws JSONException
{
if ((names == null) || (names.length() == 0) || (length() == 0))
{
return null;
}
final JSONObject jo = new JSONObject();
for (int i = 0; i < names.length(); i += 1)
{
jo.put(names.getString(i), opt(i));
}
return jo;
}
代码示例来源:origin: com.atlassian.jira/jira-api
if (index < length())
while (index != length())
put(JSONObject.NULL);
put(value);
代码示例来源:origin: com.marvelution.jira.plugins/jira-jenkins-plugin
final JSONArray actions = jsonBuild.optJSONArray("actions");
if (actions != null) {
for (int index = 0; index < actions.length(); index++) {
final JSONObject object = actions.optJSONObject(index);
if (object == null) {
continue;
for (int ii = 0; ii < causes.length(); ii++) {
final JSONObject cause = causes.getJSONObject(ii);
if (cause.has("shortDescription")) {
if (artifacts != null && artifacts.length() > 0) {
for (int index = 0; index < artifacts.length(); index++) {
final JSONObject artifact = artifacts.getJSONObject(index);
build.getArtifacts().add(new Artifact(artifact.getString("fileName"),
artifact.getString("displayPath"), artifact.getString("relativePath")));
if (culprits != null && culprits.length() > 0) {
for (int index = 0; index < culprits.length(); index++) {
final JSONObject culprit = culprits.getJSONObject(index);
String id = optJsonString(culprit, "id");
if (id == null && culprit.has("absoluteUrl")) {
if (changeSet != null && changeSet.has("items")) {
final JSONArray items = changeSet.optJSONArray("items");
if (items != null && items.length() > 0) {
for (int index = 0; index < items.length(); index++) {
final JSONObject item = items.getJSONObject(index);
String commitId = String.valueOf(index);
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Get the optional object value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return An object value, or null if there is no
* object at that index.
*/
public Object opt(final int index)
{
return ((index < 0) || (index >= length())) ? null : list.get(index);
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Put a key/value pair in the JSONObject, where the value will be a
* JSONArray which is produced from a Collection.
*
* @param key A key string.
* @param values A Collection value.
* @return this.
* @throws JSONException If the value is non-finite number or if the key is null.
*/
public JSONObject put(final String key, final Collection<Object> values) throws JSONException
{
put(key, new JSONArray(values));
return this;
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Append a boolean value. This increases the array's length by one.
*
* @param value A boolean value.
* @return this.
*/
public JSONArray put(final boolean value)
{
put(value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
代码示例来源:origin: com.atlassian.jira/jira-api
final int len = length();
((JSONArray) v).write(writer);
代码示例来源:origin: com.atlassian.jira/jira-core
for (int i = 0; i < array.length(); i++)
final Object arrayElement = array.opt(i);
if (arrayElement!=null)
代码示例来源:origin: com.atlassian.jirawallboard/atlassian-wallboard-plugin
static public WallboardPluginSettings loadSettings(PluginSettingsFactory pluginSettingsFactory, ApplicationUser user)
{
WallboardPluginSettings settings = new WallboardPluginSettings(pluginSettingsFactory, user);
Object val = pluginSettingsFactory.createGlobalSettings().get(WALLBOARD_KEY + mapNullToBlank(settings.userKey));
if (val == null)
{
settings.isConfigured = false;
return settings;
}
JSONObject jsonRepresentation;
try
{
jsonRepresentation = new JSONObject((String) val);
JSONArray rawDashboardIds = jsonRepresentation.getJSONArray("dashboardIds");
settings.dashboardIds = new ArrayList<>(rawDashboardIds.length());
for (int i = 0; i < rawDashboardIds.length(); i++)
{
settings.dashboardIds.add(i, (String) rawDashboardIds.get(i));
}
settings.setCyclePeriod(jsonRepresentation.getInt(WallboardServlet.CYCLE_PERIOD.getKey()));
settings.setTransitionFx(jsonRepresentation.getString(WallboardServlet.TRANSITION_FX.getKey()));
settings.setRandom(jsonRepresentation.getBoolean(WallboardServlet.RANDOM.getKey()));
}
catch (JSONException e)
{
settings.isConfigured = false;
}
return settings;
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Make a prettyprinted JSON text of this JSONArray.
* Warning: This method assumes that the data structure is acyclical.
*
* @param indentFactor The number of spaces to add to each level of
* indentation.
* @return a printable, displayable, transmittable
* representation of the object, beginning
* with <code>[</code> <small>(left bracket)</small> and ending
* with <code>]</code> <small>(right bracket)</small>.
* @throws JSONException if JSON object fails to convert to String
*/
public String toString(final int indentFactor) throws JSONException
{
return toString(indentFactor, 0);
}
内容来源于网络,如有侵权,请联系作者删除!