本文整理了Java中net.sf.json.JSONObject.<init>()
方法的一些代码示例,展示了JSONObject.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.<init>()
方法的具体详情如下:
包路径:net.sf.json.JSONObject
类名称:JSONObject
方法名:<init>
暂无
代码示例来源:origin: jenkinsci/jenkins
@Override
public JSONObject createContent() {
if (requestsByLanguage.size() == 0) {
return null;
}
Map<String, AtomicLong> currentRequests = new TreeMap<>(requestsByLanguage);
requestsByLanguage.clear();
JSONObject payload = new JSONObject();
for (Map.Entry<String, AtomicLong> entry : currentRequests.entrySet()) {
payload.put(entry.getKey(), entry.getValue().longValue());
}
return payload;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Create a JSON representation of a resource bundle
*
* @param bundle The resource bundle.
* @return The bundle JSON.
*/
private static JSONObject toJSONObject(@Nonnull ResourceBundle bundle) {
JSONObject json = new JSONObject();
for (String key : bundle.keySet()) {
json.put(key, bundle.getString(key));
}
return json;
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* For internal use.
*/
@JavaScriptMethod public final JSONObject news() {
lastNewsTime = System.currentTimeMillis();
JSONObject r = new JSONObject();
try {
r.put("data", data());
} catch (RuntimeException x) {
LOG.log(Level.WARNING, "failed to update " + uri, x);
status = ERROR;
}
Object statusJSON = status == 1 ? "done" : status == CANCELED ? "canceled" : status == ERROR ? "error" : status;
r.put("status", statusJSON);
if (statusJSON instanceof String) { // somehow completed
LOG.log(Level.FINE, "finished in news so releasing {0}", boundId);
release();
}
lastNewsTime = System.currentTimeMillis();
LOG.log(Level.FINER, "news from {0}", uri);
return r;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Returns whether the system needs a restart, and if it is supported
* e.g. { restartRequired: true, restartSupported: false }
*/
@Restricted(DoNotUse.class) // WebOnly
public HttpResponse doRestartStatus() throws IOException {
JSONObject response = new JSONObject();
Jenkins jenkins = Jenkins.get();
response.put("restartRequired", jenkins.getUpdateCenter().isRestartRequiredForCompletion());
response.put("restartSupported", jenkins.getLifecycle().canRestart());
return HttpResponses.okJSON(response);
}
代码示例来源:origin: jenkinsci/gitlab-plugin
@Override
protected void writeStatusBody(StaplerResponse response, Run<?, ?> build, BuildStatus status) {
try {
JSONObject object = new JSONObject();
object.put("sha", sha1);
if (build != null) {
object.put("id", build.getNumber());
}
object.put("status", status.getValue());
writeBody(response, object);
} catch (IOException e) {
throw HttpResponses.error(500, "Failed to generate response");
}
}
代码示例来源:origin: jenkinsci/jenkins
Jenkins j = Jenkins.getInstance();
JSONObject o = new JSONObject();
o.put("stat",1);
o.put("install", j.getLegacyInstanceId());
o.put("servletContainer", j.servletContext.getServerInfo());
o.put("version", Jenkins.VERSION);
JSONObject n = new JSONObject();
if(c.getNode()==j) {
n.put("master",true);
for( PluginWrapper pw : j.getPluginManager().getPlugins() ) {
if(!pw.isActive()) continue; // treat disabled plugins as if they are uninstalled
JSONObject p = new JSONObject();
p.put("name",pw.getShortName());
p.put("version",pw.getVersion());
o.put("plugins",plugins);
JSONObject jobs = new JSONObject();
代码示例来源:origin: jenkinsci/jenkins
Map<String,JSONObject> allPlugins = new HashMap<>();
for (PluginWrapper plugin : plugins) {
JSONObject pluginInfo = new JSONObject();
pluginInfo.put("installed", true);
pluginInfo.put("name", plugin.getShortName());
pluginInfo.put("title", plugin.getDisplayName());
pluginInfo.put("active", plugin.isActive());
pluginInfo.put("enabled", plugin.isEnabled());
JSONObject pluginInfo = allPlugins.get(plugin.name);
if(pluginInfo == null) {
pluginInfo = new JSONObject();
pluginInfo.put("installed", false);
代码示例来源:origin: jenkinsci/jenkins
JSONObject data = new JSONObject();
try {
data = telemetry.createContent();
JSONObject wrappedData = new JSONObject();
wrappedData.put("type", telemetry.getId());
wrappedData.put("payload", data);
String correlationId = ExtensionList.lookupSingleton(Correlator.class).getCorrelationId();
wrappedData.put("correlator", DigestUtils.sha256Hex(correlationId + telemetry.getId()));
代码示例来源:origin: jenkinsci/jenkins
/**
* Installs a list of plugins from a JSON POST.
* @param req The request object.
* @return A JSON response that includes a "correlationId" in the "data" element.
* That "correlationId" can then be used in calls to
* {@link UpdateCenter#doInstallStatus(org.kohsuke.stapler.StaplerRequest)}.
* @throws IOException Error reading JSON payload fro request.
*/
@RequirePOST
@Restricted(DoNotUse.class) // WebOnly
public HttpResponse doInstallPlugins(StaplerRequest req) throws IOException {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
String payload = IOUtils.toString(req.getInputStream(), req.getCharacterEncoding());
JSONObject request = JSONObject.fromObject(payload);
JSONArray pluginListJSON = request.getJSONArray("plugins");
List<String> plugins = new ArrayList<>();
for (int i = 0; i < pluginListJSON.size(); i++) {
plugins.add(pluginListJSON.getString(i));
}
UUID correlationId = UUID.randomUUID();
try {
boolean dynamicLoad = request.getBoolean("dynamicLoad");
install(plugins, dynamicLoad, correlationId);
JSONObject responseData = new JSONObject();
responseData.put("correlationId", correlationId.toString());
return hudson.util.HttpResponses.okJSON(responseData);
} catch (Exception e) {
return hudson.util.HttpResponses.errorJSON(e.getMessage());
}
}
代码示例来源:origin: geoserver/geoserver
/**
* @param list the list of layer identifiers to serialize
* @return {@code null} if {@code list} is null, empty or contains only null objects; the JSON
* array representation of {@code list} otherwise, with any null element stripped off.
*/
public static String toString(List<AuthorityURLInfo> obj) {
if (obj == null || obj.isEmpty()) {
return null;
}
JSONArray array = new JSONArray();
for (AuthorityURLInfo auth : obj) {
if (auth == null) {
continue;
}
JSONObject jsonAuth = new JSONObject();
jsonAuth.put(NAME, auth.getName());
jsonAuth.put(HREF, auth.getHref());
array.add(jsonAuth);
}
if (array.size() == 0) {
// list was made of only null objects?
return null;
}
String serialized = array.toString();
return serialized;
}
}
代码示例来源:origin: geoserver/geoserver
/**
* @param list the list of auth urls to serialize
* @return {@code null} if {@code list} is null, empty, or contains only null objects; the JSON
* array representation of {@code list} otherwise, with any null element stripped off.
*/
public static String toString(List<LayerIdentifierInfo> list) {
if (list == null || list.isEmpty()) {
return null;
}
JSONArray array = new JSONArray();
for (LayerIdentifierInfo id : list) {
if (id == null) {
continue;
}
JSONObject jsonId = new JSONObject();
jsonId.put(AUTHORITY, id.getAuthority());
jsonId.put(IDENTIFIER, id.getIdentifier());
array.add(jsonId);
}
if (array.size() == 0) {
// list was made of only null objects?
return null;
}
String serialized = array.toString();
return serialized;
}
}
代码示例来源:origin: kongzhidea/pay
public static JSONObject getJsonObject(String key, String value) {
JSONObject json = new JSONObject();
json.put(key, value);
return json;
}
代码示例来源:origin: kongzhidea/pay
public static JSONObject getJson(int code)
{
JSONObject json = new JSONObject();
json.put("code",code);
return json;
}
public static JSONObject getJson(int code, String msg) {
代码示例来源:origin: kongzhidea/pay
public static JSONObject getJson(String code , String message) {
// TODO Auto-generated method stub
JSONObject json = new JSONObject();
json.put("code", code);
json.put("msg", message);
return json;
}
代码示例来源:origin: kongzhidea/pay
public static JSONObject getErrJson(int code, String message) {
final JSONObject json = new JSONObject();
json.put("code", code);
json.put("msg", message);
return json;
}
代码示例来源:origin: kongzhidea/pay
public static JSONObject getOkJson(String msg) {
JSONObject json = new JSONObject();
json.put("code", JSON_CODE_OK);
json.put("msg", msg);
return json;
}
代码示例来源:origin: kongzhidea/pay
public static JSONObject getErrorJsonResult(String message) {
JSONObject json = new JSONObject();
json.put("statusCode", 300);
json.put("message", message);
return json;
}
代码示例来源:origin: kongzhidea/pay
public static JSONObject getTechnicianJson(String message) {
// TODO Auto-generated method stub
JSONObject json = new JSONObject();
json.put("code", "20003");
json.put("msg", message);
return json;
}
代码示例来源:origin: kongzhidea/pay
public static JSONObject getJson(int code, String msg) {
JSONObject json = new JSONObject();
json.put("code", code+"");
json.put("msg", msg);
return json;
}
代码示例来源:origin: kongzhidea/pay
public static JSONObject getJson(int code, int left)
{
JSONObject json = new JSONObject();
json.put("code", code);
json.put("left", left);
return json;
}
内容来源于网络,如有侵权,请联系作者删除!