當前位置: 首頁>>代碼示例>>Java>>正文


Java Json.object方法代碼示例

本文整理匯總了Java中com.eclipsesource.json.Json.object方法的典型用法代碼示例。如果您正苦於以下問題:Java Json.object方法的具體用法?Java Json.object怎麽用?Java Json.object使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.eclipsesource.json.Json的用法示例。


在下文中一共展示了Json.object方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setup

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
public void setup(String keyword, String username, String password) {
	LOG.info("setup: " + username);
	HttpPost m = new HttpPost(baseUrl + "/api/v1/setup/setup");
	JsonObject json = Json.object();
	json.add("keyword", keyword);
	json.add("username", username);
	json.add("password", password);
	m.setEntity(new StringEntity(json.toString(), ContentType.APPLICATION_JSON));
	HttpResponse response = null;
	try {
		response = httpclient.execute(m);
		int statusCode = response.getStatusLine().getStatusCode();
		if (statusCode != HttpStatus.SC_OK) {
			LOG.info("response: " + EntityUtils.toString(response.getEntity()));
			throw new RuntimeException("invalid status code: " + statusCode);
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	} finally {
		if (response != null) {
			EntityUtils.consumeQuietly(response.getEntity());
		}
	}
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:25,代碼來源:RestClient.java

示例2: doGet

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
@Override
public ModelAndView doGet(IHTTPSession session) {
	ModelAndView result = new ModelAndView();
	JsonObject entity = Json.object();
	for (Entry<String, Result> cur : Metrics.HEALTH_REGISTRY.runHealthChecks().entrySet()) {
		JsonObject value = Json.object().add("status", cur.getValue().getDetails().get("status").toString());
		if (!cur.getValue().isHealthy()) {
			value.add("message", cur.getValue().getMessage());
		}
		entity.add(cur.getKey(), value);
	}
	result.setData(entity.toString());
	return result;
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:15,代碼來源:Overview.java

示例3: doLogin

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
public static ModelAndView doLogin(Authenticator auth, String username, String password) {
	String token = auth.authenticate(username, password);
	ModelAndView result = new ModelAndView();
	if (token == null) {
		result.setData(new ValidationResult("Invalid login or password").toJson());
		result.setStatus(Response.Status.UNAUTHORIZED);
	} else {
		JsonObject data = Json.object();
		data.add("access_token", token);
		data.add("token_type", "bearer");
		data.add("expires_in", auth.getMaxAgeMillis() / 1000);
		result.setData(data.toString());
	}
	return result;
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:16,代碼來源:AccessToken.java

示例4: toJson

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
public String toJson() {
	JsonObject result = Json.object();
	if (!isEmpty()) {
		JsonObject errors = Json.object();
		if (general != null) {
			errors.add("general", general);
		}
		for (Entry<String, String> cur : entrySet()) {
			errors.add(cur.getKey(), cur.getValue());
		}
		result.add("errors", errors);
	}
	return result.toString();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:15,代碼來源:ValidationResult.java

示例5: save

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
/**
 * Save current settings to configuration.
 */
public void save() {
	try {
		if (!confFile.exists() && !confFile.createNewFile()) {
			// Return if config file cannot be found and cannot be created.
			return;
		}
		JsonObject json = Json.object();
		for (Field field : this.getClass().getDeclaredFields()) {
			// Skip private and static fields.
			int mod = field.getModifiers();
			if (Modifier.isPrivate(mod) || Modifier.isStatic(mod)) {
				continue;
			}
			// Access via reflection, add value to json object.
			field.setAccessible(true);
			String name = field.getName();
			Object value = field.get(this);
			if (value instanceof Boolean) {
				json.set(name, (boolean) value);
			} else if (value instanceof Integer) {
				json.set(name, (int) value);
			} else if (value instanceof String) {
				json.set(name, (String) value);
			} else {
				JsonValue converted = convert(field.getType(), value);
				if (converted != null) {
					json.set(name, converted);
				}
			}
		}
		// Write json to file
		StringWriter w = new StringWriter();
		json.writeTo(w, WriterConfig.PRETTY_PRINT);
		Files.writeFile(confFile.getAbsolutePath(), w.toString());
	} catch (Exception e) {
		Recaf.INSTANCE.logging.error(e);
	}
}
 
開發者ID:Col-E,項目名稱:Recaf,代碼行數:42,代碼來源:Config.java


注:本文中的com.eclipsesource.json.Json.object方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。