本文整理了Java中net.sf.json.JSONObject.has()
方法的一些代码示例,展示了JSONObject.has()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.has()
方法的具体详情如下:
包路径:net.sf.json.JSONObject
类名称:JSONObject
方法名:has
暂无
代码示例来源:origin: jenkinsci/jenkins
private static String get(JSONObject o, String prop) {
if(o.has(prop))
return o.getString(prop);
else
return null;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Accept anything as value for the {@link #REDACT_KEY} but only process the first level of an array and the string value.
*/
private Set<String> retrieveRedactedKeys(JSONObject jsonObject) {
Set<String> redactedKeySet = new HashSet<>();
if (jsonObject.has(REDACT_KEY)) {
Object value = jsonObject.get(REDACT_KEY);
if (value instanceof JSONArray) {
for (Object o : jsonObject.getJSONArray(REDACT_KEY)) {
if (o instanceof String) {
redactedKeySet.add((String) o);
} else {
// array, object, null, number, boolean
LOGGER.log(Level.WARNING, "Unsupported type " + o.getClass().getName() + " for " + REDACT_KEY + ", please use either a single String value or an Array");
}
}
} else if (value instanceof String) {
redactedKeySet.add((String) value);
} else {
// object, null, number, boolean
LOGGER.log(Level.WARNING, "Unsupported type " + value.getClass().getName() + " for " + REDACT_KEY + ", please use either a single String value or an Array");
}
}
return redactedKeySet;
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
if (isRelevant()) {
// don't record on/off unless this becomes relevant, so that we can differentiate
// those who have disabled vs those who haven't cared.
rule.setMasterKillSwitch(!json.has("masterToSlaveAccessControl"));
}
return true;
}
代码示例来源:origin: jenkinsci/jenkins
private boolean needToAddToCurrentView(StaplerRequest req) throws ServletException {
String json = req.getParameter("json");
if (json != null && json.length() > 0) {
// Submitted via UI
JSONObject form = req.getSubmittedForm();
return form.has("addToCurrentView") && form.getBoolean("addToCurrentView");
} else {
// Submitted via API
return true;
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
try {
// for backward compatibility reasons, this configuration is stored in Jenkins
Jenkins.getInstance().setNoUsageStatistics(json.has("usageStatisticsCollected") ? null : true);
return true;
} catch (IOException e) {
throw new FormException(e,"usageStatisticsCollected");
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
*
* @param o the {@link JSONObject} representing the warning
* @throws JSONException if the argument does not match the expected format
*/
@Restricted(NoExternalUse.class)
public Warning(JSONObject o) {
try {
this.type = Type.valueOf(o.getString("type").toUpperCase(Locale.US));
} catch (IllegalArgumentException ex) {
this.type = Type.UNKNOWN;
}
this.id = o.getString("id");
this.component = Util.intern(o.getString("name"));
this.message = o.getString("message");
this.url = o.getString("url");
if (o.has("versions")) {
JSONArray versions = o.getJSONArray("versions");
List<WarningVersionRange> ranges = new ArrayList<>(versions.size());
for (int i = 0; i < versions.size(); i++) {
WarningVersionRange range = new WarningVersionRange(versions.getJSONObject(i));
ranges.add(range);
}
this.versionRanges = Collections.unmodifiableList(ranges);
} else {
this.versionRanges = Collections.emptyList();
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
// for compatibility reasons, the actual value is stored in Jenkins
Jenkins j = Jenkins.get();
if (json.has("primaryView")) {
final String viewName = json.getString("primaryView");
final View newPrimaryView = j.getView(viewName);
if (newPrimaryView == null) {
throw new FormException(Messages.GlobalDefaultViewConfiguration_ViewDoesNotExist(viewName), "primaryView");
}
j.setPrimaryView(newPrimaryView);
} else {
// Fallback if the view is not specified
j.setPrimaryView(j.getViews().iterator().next());
}
return true;
}
}
代码示例来源:origin: jenkinsci/jenkins
@DataBoundConstructor
public Plugin(String sourceId, JSONObject o) {
super(sourceId, o, UpdateSite.this.url);
this.wiki = get(o,"wiki");
this.title = get(o,"title");
this.excerpt = get(o,"excerpt");
this.compatibleSinceVersion = Util.intern(get(o,"compatibleSinceVersion"));
this.minimumJavaVersion = Util.intern(get(o, "minimumJavaVersion"));
this.requiredCore = Util.intern(get(o,"requiredCore"));
this.categories = o.has("labels") ? internInPlace((String[])o.getJSONArray("labels").toArray(EMPTY_STRING_ARRAY)) : null;
JSONArray ja = o.getJSONArray("dependencies");
int depCount = (int)(ja.stream().filter(IS_DEP_PREDICATE.and(IS_NOT_OPTIONAL)).count());
int optionalDepCount = (int)(ja.stream().filter(IS_DEP_PREDICATE.and(IS_NOT_OPTIONAL.negate())).count());
dependencies = getPresizedMutableMap(depCount);
optionalDependencies = getPresizedMutableMap(optionalDepCount);
for(Object jo : o.getJSONArray("dependencies")) {
JSONObject depObj = (JSONObject) jo;
// Make sure there's a name attribute and that the optional value isn't true.
String depName = Util.intern(get(depObj,"name"));
if (depName!=null) {
if (get(depObj, "optional").equals("false")) {
dependencies.put(depName, Util.intern(get(depObj, "version")));
} else {
optionalDependencies.put(depName, Util.intern(get(depObj, "version")));
}
}
}
}
代码示例来源:origin: jenkinsci/jenkins
private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor<?> d) throws FormException {
// collapse the structure to remain backward compatible with the JSON structure before 1.
String name = d.getJsonSafeClassName();
JSONObject js = json.has(name) ? json.getJSONObject(name) : new JSONObject(); // if it doesn't have the property, the method returns invalid null object.
json.putAll(js);
return d.configure(req, js);
}
代码示例来源:origin: jenkinsci/jenkins
private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor<?> d) throws Descriptor.FormException {
String name = d.getJsonSafeClassName();
JSONObject js = json.has(name) ? json.getJSONObject(name) : new JSONObject(); // if it doesn't have the property, the method returns invalid null object.
json.putAll(js);
return d.configure(req, js);
}
代码示例来源:origin: jenkinsci/jenkins
private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor<?> d) throws FormException {
// collapse the structure to remain backward compatible with the JSON structure before 1.
String name = d.getJsonSafeClassName();
JSONObject js = json.has(name) ? json.getJSONObject(name) : new JSONObject(); // if it doesn't have the property, the method returns invalid null object.
json.putAll(js);
return d.configure(req, js);
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
// for compatibility reasons, the actual value is stored in Jenkins
Jenkins j = Jenkins.get();
if (json.has("myViewsTabBar")) {
j.setMyViewsTabBar(req.bindJSON(MyViewsTabBar.class,json.getJSONObject("myViewsTabBar")));
} else {
j.setMyViewsTabBar(new DefaultMyViewsTabBar());
}
return true;
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
// for compatibility reasons, the actual value is stored in Jenkins
Jenkins j = Jenkins.get();
if (json.has("viewsTabBar")) {
j.setViewsTabBar(req.bindJSON(ViewsTabBar.class,json.getJSONObject("viewsTabBar")));
} else {
j.setViewsTabBar(new DefaultViewsTabBar());
}
return true;
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
// for compatibility reasons, the actual value is stored in Jenkins
Jenkins j = Jenkins.get();
if (json.has("csrf")) {
JSONObject csrf = json.getJSONObject("csrf");
j.setCrumbIssuer(CrumbIssuer.all().newInstanceFromRadioList(csrf, "issuer"));
} else {
j.setCrumbIssuer(null);
}
return true;
}
}
代码示例来源:origin: jenkinsci/jenkins
if (pluginData instanceof JSONObject) {
JSONObject plugin = (JSONObject)pluginData;
if (plugin.has("added")) {
String sinceVersion = plugin.getString("added");
if (sinceVersion != null) {
代码示例来源:origin: jenkinsci/jenkins
if(json.optBoolean("hasCustomQuietPeriod", json.has("quiet_period"))) {
quietPeriod = json.optInt("quiet_period");
} else {
if(json.optBoolean("hasCustomScmCheckoutRetryCount", json.has("scmCheckoutRetryCount"))) {
scmCheckoutRetryCount = json.optInt("scmCheckoutRetryCount");
} else {
} else if(json.optBoolean("hasCustomWorkspace", json.has("customWorkspace"))) {
customWorkspace = Util.fixEmptyAndTrim(json.optString("customWorkspace"));
} else {
if (json.has("scmCheckoutStrategy"))
scmCheckoutStrategy = req.bindJSON(SCMCheckoutStrategy.class,
json.getJSONObject("scmCheckoutStrategy"));
scmCheckoutStrategy = null;
if(json.optBoolean("hasSlaveAffinity", json.has("label"))) {
assignedNode = Util.fixEmptyAndTrim(json.optString("label"));
} else if(req.hasParameter("_.assignedLabelString")) {
keepDependencies = json.has("keepDependencies");
代码示例来源:origin: jenkinsci/jenkins
if (json.has("useSecurity")) {
JSONObject security = json.getJSONObject("useSecurity");
j.setDisableRememberMe(security.optBoolean("disableRememberMe", false));
if (json.has("markupFormatter")) {
j.setMarkupFormatter(req.bindJSON(MarkupFormatter.class, json.getJSONObject("markupFormatter")));
} else {
if (json.has("agentProtocol")) {
Object protocols = json.get("agentProtocol");
if (protocols instanceof JSONArray) {
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
try {
// for backward compatibility reasons, this configuration is stored in Jenkins
Jenkins.getInstance().setNoUsageStatistics(json.has("usageStatisticsCollected") ? null : true);
return true;
} catch (IOException e) {
throw new FormException(e,"usageStatisticsCollected");
}
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor<?> d) throws Descriptor.FormException {
String name = d.getJsonSafeClassName();
JSONObject js = json.has(name) ? json.getJSONObject(name) : new JSONObject(); // if it doesn't have the property, the method returns invalid null object.
json.putAll(js);
return d.configure(req, js);
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
// for compatibility reasons, the actual value is stored in Jenkins
Jenkins j = Jenkins.getInstance();
if (json.has("myViewsTabBar")) {
j.setMyViewsTabBar(req.bindJSON(MyViewsTabBar.class,json.getJSONObject("myViewsTabBar")));
} else {
j.setMyViewsTabBar(new DefaultMyViewsTabBar());
}
return true;
}
}
内容来源于网络,如有侵权,请联系作者删除!