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


Java Json.parse方法代碼示例

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


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

示例1: getTle

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
public JsonObject getTle() {
	LOG.info("get tle");
	HttpGet m = new HttpGet(baseUrl + "/api/v1/admin/tle");
	m.addHeader("Authorization", "Bearer " + accessToken);
	HttpResponse response = null;
	try {
		response = httpclient.execute(m);
		int statusCode = response.getStatusLine().getStatusCode();
		String responseBody = EntityUtils.toString(response.getEntity());
		if (statusCode != HttpStatus.SC_OK) {
			LOG.info("response: " + responseBody);
			throw new RuntimeException("invalid status code: " + statusCode);
		}
		return (JsonObject) Json.parse(responseBody);
	} catch (Exception e) {
		throw new RuntimeException(e);
	} finally {
		if (response != null) {
			EntityUtils.consumeQuietly(response.getEntity());
		}
	}
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:23,代碼來源:RestClient.java

示例2: executeCommandAndGetJsonValue

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
private JsonValue executeCommandAndGetJsonValue(String command1, String command2, String command3)
	throws WalletCallException, IOException, InterruptedException
{
	String strResponse = this.executeCommandAndGetSingleStringResponse(command1, command2, command3);

	JsonValue response = null;
	try
	{
	  	response = Json.parse(strResponse);
	} catch (ParseException pe)
	{
	  	throw new WalletCallException(strResponse + "\n" + pe.getMessage() + "\n", pe);
	}

	return response;
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:17,代碼來源:ZCashClientCaller.java

示例3: doPost

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}
	ValidationResult errors = new ValidationResult();
	String username = ((JsonObject) request).getString("username", null);
	if (username == null || username.trim().length() == 0) {
		errors.put("username", "Cannot be empty");
	}
	if (!errors.isEmpty()) {
		LOG.info("unable to save: " + errors);
		return new BadRequest(errors);
	}
	auth.resetPassword(username);
	return new Success();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:19,代碼來源:Restore.java

示例4: doPost

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}
	ValidationResult errors = new ValidationResult();
	Double lat = WebServer.getDouble(request, "lat");
	Double lon = WebServer.getDouble(request, "lng");
	if (lat == null) {
		errors.put("lat", "Cannot be empty");
	}
	if (lon == null) {
		errors.put("lng", "Cannot be empty");
	}
	if (!errors.isEmpty()) {
		LOG.info("unable to save: " + errors);
		return new BadRequest(errors);
	}
	autoUpdate.setEnabled(WebServer.getBoolean(request, "autoUpdate"));
	config.setProperty("locaiton.lat", String.valueOf(lat));
	config.setProperty("locaiton.lon", String.valueOf(lon));
	config.update();
	return new Success();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:26,代碼來源:General.java

示例5: doPost

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}

	boolean sslEnabled = WebServer.getBoolean(request, "enabled");
	boolean agreeWithToC = WebServer.getBoolean(request, "agreeWithToC");
	String domain = ((JsonObject) request).getString("domain", null);

	ValidationResult errors = new ValidationResult();
	if (sslEnabled && !agreeWithToC) {
		errors.put("agreeWithToC", "You must agree with ToC");
	}
	if (domain == null || domain.trim().length() == 0) {
		errors.put("domain", "Cannot be empty");
	}

	if (!errors.isEmpty()) {
		LOG.info("unable to save: " + errors);
		return new BadRequest(errors);
	}

	if (sslEnabled && !acmeClient.isSSLEnabled()) {
		config.setProperty("acme.ssl.domain", domain);
		config.update();
		acmeClient.setup();
	}

	return new Success();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:33,代碼來源:SSL.java

示例6: doPost

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}

	boolean agreeWithToC = WebServer.getBoolean(request, "agreeWithToC");
	ValidationResult errors = new ValidationResult();
	if (!agreeWithToC) {
		errors.put("agreeWithToC", "You must agree with ToC");
	}

	if (!errors.isEmpty()) {
		LOG.info("unable to save: " + errors);
		return new BadRequest(errors);
	}
	
	LOG.info("enable weather satellites");

	try (BufferedWriter w = new BufferedWriter(new FileWriter(config.getProperty("satellites.wxtoimg.license.path")))) {
		w.append("2.11.2 beta\n");
	} catch (Exception e) {
		LOG.error("unable to write license file", e);
		return new InternalServerError();
	}
	config.setProperty("satellites.enabled", true);
	config.update();

	return new Success();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:32,代碼來源:WeatherConfig.java

示例7: doPost

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}
	String username = ((JsonObject) request).getString("username", null);
	String password = ((JsonObject) request).getString("password", null);
	return doLogin(auth, username, password);
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:11,代碼來源:AccessToken.java

示例8: doPost

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}
	ValidationResult errors = new ValidationResult();
	
	String username = ((JsonObject) request).getString("username", null);
	String password = ((JsonObject) request).getString("password", null);
	String keyword = ((JsonObject) request).getString("keyword", null);
	
	if (username == null || username.trim().length() == 0) {
		errors.put("username", "Cannot be empty");
	}
	if (password == null || password.trim().length() == 0) {
		errors.put("password", "Cannot be empty");
	}
	if (keyword == null || keyword.trim().length() == 0) {
		errors.put("keyword", "Cannot be empty");
	}

	if (!errors.isEmpty()) {
		LOG.info("unable to save: " + errors);
		return new BadRequest(errors);
	}

	// keyword location extracted for dev environment
	try (BufferedReader r = new BufferedReader(new FileReader(config.getProperty("server.keyword.location")))) {
		String actualKeyword = r.readLine();
		// actualKeyword can be null here
		// keyword should not be null here. However eclipse complains about
		// potential npe.
		if (keyword == null || !keyword.equals(actualKeyword)) {
			errors.put("keyword", "Invalid keyword");
		}
	} catch (Exception e) {
		String message = "unable to read r2cloud file. ";
		if (LOG.isDebugEnabled()) {
			LOG.debug(message, e);
		} else {
			LOG.info(message + e.getMessage());
		}
		errors.setGeneral("Unable to read r2cloud file");
	}

	if (!errors.isEmpty()) {
		LOG.info("unable to save: " + errors);
		return new BadRequest(errors);
	}

	auth.setPassword(username, password);

	return AccessToken.doLogin(auth, username, password);
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:56,代碼來源:Setup.java

示例9: doPost

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}
	String satelliteId = ((JsonObject) request).getString("satelliteId", null);
	String id = ((JsonObject) request).getString("id", null);
	if (id == null || satelliteId == null) {
		LOG.info("missing parameters");
		return new BadRequest("missing parameters");
	}
	ObservationResult observation = dao.find(satelliteId, id);
	if (observation == null) {
		LOG.info("not found: " + satelliteId + " id: " + id);
		return new NotFound();
	}

	if (observation.getWavPath() == null || !observation.getWavPath().exists()) {
		LOG.info("wav file not found");
		return new NotFound();
	}

	try (InputStream is = new BufferedInputStream(new FileInputStream(observation.getWavPath()))) {
		WavFileSource source = new WavFileSource(is);
		BufferedImage image = waterfall.process(source);
		File tmp = File.createTempFile(observation.getId() + "-", "-spectogram.png");
		ImageIO.write(image, "png", tmp);
		if (!dao.saveSpectogram(satelliteId, id, tmp)) {
			LOG.info("unable to save spectogram");
			return new InternalServerError();
		}
	} catch (Exception e) {
		LOG.error("unable to create waterfall", e);
		return new InternalServerError();
	}
	observation = dao.find(satelliteId, id);
	JsonObject entity = new JsonObject();
	entity.add("spectogramURL", observation.getSpectogramURL());
	ModelAndView result = new ModelAndView();
	result.setData(entity.toString());
	return result;
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:44,代碼來源:WeatherSpectrogram.java

示例10: doPost

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}

	DDNSType type = DDNSType.valueOf(((JsonObject) request).getString("type", null));
	String username = ((JsonObject) request).getString("username", null);
	String password = ((JsonObject) request).getString("password", null);
	String domain = ((JsonObject) request).getString("domain", null);

	ValidationResult errors = new ValidationResult();
	switch (type) {
	case NOIP:
		if (username == null || username.trim().length() == 0) {
			errors.put("username", "Field is required");
		}
		if (password == null || password.trim().length() == 0) {
			errors.put("password", "Field is required");
		}
		if (domain == null || domain.trim().length() == 0) {
			errors.put("domain", "Field is required");
		}
		break;
	default:
		break;
	}

	if (!errors.isEmpty()) {
		LOG.info("unable to save: " + errors);
		return new BadRequest(errors);
	}

	config.setProperty("ddns.noip.username", username);
	config.setProperty("ddns.noip.password", password);
	config.setProperty("ddns.noip.domain", domain);
	config.setProperty("ddns.type", type.name());
	config.update();

	ddnsClient.stop();
	ddnsClient.start();

	return new Success();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:46,代碼來源:DDNS.java

示例11: jsonFromUrl

import com.eclipsesource.json.Json; //導入方法依賴的package包/類
/**
 * Returns json value for given String url
 * @param url url to connect to
 * @return
 */
public static JsonValue jsonFromUrl(String url) throws IOException {
	return Json.parse(stringFromUrl(url));
}
 
開發者ID:paul-io,項目名稱:momo-2,代碼行數:9,代碼來源:Util.java


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