• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JSONObject类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中us.monoid.json.JSONObject的典型用法代码示例。如果您正苦于以下问题:Java JSONObject类的具体用法?Java JSONObject怎么用?Java JSONObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JSONObject类属于us.monoid.json包,在下文中一共展示了JSONObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getDevices

import us.monoid.json.JSONObject; //导入依赖的package包/类
public List<HomeWizardSmartPlugDevice> getDevices() 
{
	List<HomeWizardSmartPlugDevice> homewizardDevices = new ArrayList<>();	
	try {
		
		String result = requestJson(EMPTY_STRING);
		JSONObject resultJson = new JSONObject(result);
		cloudPlugId = resultJson.getString("id");
	
		String all_devices_json = resultJson.get("devices").toString();
		Device[] devices = gson.fromJson(all_devices_json, Device[].class);
		
		// Fix names from JSON
		for (Device device : devices) {
			device.setTypeName(StringUtils.capitalize(device.getTypeName().replace("_", " ")));
			homewizardDevices.add(mapDeviceToHomeWizardSmartPlugDevice(device));
		}
	}
	catch(JSONException e) {
		log.warn("Error while get devices from cloud service ", e);
	}
	
	log.info("Found: " + homewizardDevices.size() + " devices");
	return homewizardDevices;
}
 
开发者ID:bwssytems,项目名称:ha-bridge,代码行数:26,代码来源:HomeWizzardSmartPlugInfo.java


示例2: execApply

import us.monoid.json.JSONObject; //导入依赖的package包/类
public void execApply(String jsonToPost) throws JSONException, IOException {
		
	// Extract 
	JSONObject resultJson = new JSONObject(jsonToPost);
	String deviceId = resultJson.getString("deviceid");
	String action = resultJson.getString("action");
	
	// Check if we have an plug id stored
	if (StringUtils.isBlank(cloudPlugId)) {
		getDevices();
	}
	
	// Send request to HomeWizard cloud
	if (!sendAction("/" + cloudPlugId + "/devices/" + deviceId + "/action", action))
	{
		throw new IOException("Send action to HomeWizard Cloud failed.");
	}
}
 
开发者ID:bwssytems,项目名称:ha-bridge,代码行数:19,代码来源:HomeWizzardSmartPlugInfo.java


示例3: getJSON

import us.monoid.json.JSONObject; //导入依赖的package包/类
/**
	 * @param url
	 * @return Returns the JSON 
	 */
	private String getJSON(String url){
		JSONResource res = null;
		JSONObject obj = null;
		Resty resty = new Resty();
		
		try {
			res = resty.json(url);
			obj = res.toObject();
			
		} catch (IOException | JSONException e) {
			// TODO: not my favorite way but does the trick
//			e.printStackTrace();
			return getJSON(url);
		}
		
		return obj.toString();
	}
 
开发者ID:U-QASAR,项目名称:u-qasar.platform,代码行数:22,代码来源:AnalysisDrilldown.java


示例4: getDataFromDimension

import us.monoid.json.JSONObject; //导入依赖的package包/类
/**
 * @param jsonObject
 * @return Return a List with all the data from JSON 
 */
private List<String> getDataFromDimension(String jsonObject) {
	List<String> data = new ArrayList<>();
	try {
		JSONObject jobj = new JSONObject(jsonObject);
		us.monoid.json.JSONArray jsonArray = jobj.getJSONArray("cells");
		
		for (int i = 0; i < jsonArray.length() ; i++) {
			JSONObject row = jsonArray.getJSONObject(i);
			
			data.add(row.toString());
		}
		
	} catch (JSONException e) {
		e.printStackTrace();
	}
	
	return data;
}
 
开发者ID:U-QASAR,项目名称:u-qasar.platform,代码行数:23,代码来源:AnalysisDrilldown.java


示例5: nextPage

import us.monoid.json.JSONObject; //导入依赖的package包/类
/**
 * Attempt to request the next page using the next link from the current page
 * @return a BundleSearchResults representing the next page, or null if there are no other pages
 * @throws JSONException if the href for the next link could not be obtained for some reason
 * @throws IOException if a network failure occurred while fetching the next page
 */
public BundleSearchResults nextPage() throws JSONException, IOException {
    if(!hasNextPage()) {
        return null;
    }
    
    JSONObject nextLink = nextLink();
    if(nextLink != null) {
        String href = (String)nextLink.get("href");
        JSONResource jsonResource = 
                client.json(client.buildPathFromHref(href));
        ClarifyResponse resp = new ClarifyResponse(jsonResource);
        BundleSearchResults results = new BundleSearchResults(client, resp);
        return results;
    }
    return null;
}
 
开发者ID:Clarify,项目名称:clarify-java,代码行数:23,代码来源:BundleSearchResults.java


示例6: nextPage

import us.monoid.json.JSONObject; //导入依赖的package包/类
/**
 * Attempt to request the next page using the next link from the current page
 * @return a BundleList representing the next page, or null if there are no other pages
 * @throws JSONException if the href for the next link could not be obtained for some reason
 * @throws IOException if a network failure occurred while fetching the next page
 */
public BundleList nextPage() throws JSONException, IOException {
    if(!hasNextPage()) {
        return null;
    }
    
    JSONObject nextLink = nextLink();
    if(nextLink != null) {
        String href = (String)nextLink.get("href");
        JSONResource jsonResource = 
                client.json(client.buildPathFromHref(href));
        ClarifyResponse resp = new ClarifyResponse(jsonResource);
        BundleList list = new BundleList(client, resp);
        return list;
    }
    return null;
}
 
开发者ID:Clarify,项目名称:clarify-java,代码行数:23,代码来源:BundleList.java


示例7: updateMetadata

import us.monoid.json.JSONObject; //导入依赖的package包/类
/**
 * Updates the user-defined data property of the Bundle's Metadata with the supplied JSON string, 
 * then return a refreshed copy (resulting in 2 API calls)
 * @param bundleId the GUID of the Bundle for updating the Metadata
 * @param json a String containing valid JSON, or null. If null is passed, then the data is reset to a JSON equiv of {}
 * @return a refreshed Metadata instance for the media bundle
 * @throws IOException if a failure occurred during the API,  
 * typically a 4xx HTTP error code + JSON payload with the error message and details
 */
public BundleMetadata updateMetadata(String bundleId, String json) throws IOException {
    if(bundleId == null) {
        throw new RuntimeException("bundleId cannot be null");
    }
    if(json == null) {
        json = "{}";
    }
    
    // wrap the request in a JSON payload with a data property that contains the user JSON data to update
    JSONObject payload = null;
    try {
        payload = new JSONObject().put("data", json);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    JSONResource jsonResource = 
            json(buildPathFromResourcePath("/bundles/"+bundleId+"/metadata"), put(content(payload)));

    // re-retrieve
    return findMetadata(bundleId);
}
 
开发者ID:Clarify,项目名称:clarify-java,代码行数:31,代码来源:ClarifyClient.java


示例8: execute

import us.monoid.json.JSONObject; //导入依赖的package包/类
@Override
public HttpResponse execute(final String url, final String jsonRequestBody) {
    HttpURLConnection httpConnection = null;
    try {
        final Resty resty = new Resty();
        if (isProxySet()) {
            resty.setProxy(proxyHost, proxyPort);
        }
        final TextResource textResource = resty.text(url, content(new JSONObject(jsonRequestBody)));
        httpConnection = textResource.http();

        return toHttpResponse(textResource, httpConnection);

    } catch (IOException ioEx) {
        throw new HipChatNotificationPluginException("Error opening connection to HipChat URL: [" + ioEx.getMessage() + "].", ioEx);

    } catch (JSONException jsonEx) {
        throw new HipChatNotificationPluginException("Malformed JSON request body: [" + jsonEx.getMessage() + "].", jsonEx);

    } finally {
        if (httpConnection != null) {
            httpConnection.disconnect();
        }
    }
}
 
开发者ID:hbakkum,项目名称:rundeck-hipchat-plugin,代码行数:26,代码来源:RestyHttpRequestExecutor.java


示例9: accquireToken

import us.monoid.json.JSONObject; //导入依赖的package包/类
private String accquireToken() throws RestClientException {
	String securityToken = null;
	if (!isServiceRunning()) {
		throw new RestClientException("Id service is not currently running at URL:" + idServiceUrl);
	}
	LOGGER.info("Id service rest client logs in to get a new security token." );
	try {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("username", this.userName);
		jsonObject.put("password", this.password);
		securityToken = (String) resty.json(urlHelper.getLoginUrl(), RestyHelper.content(jsonObject)).get(TOKEN);
		LOGGER.info("Security token is acquired successfully:" + securityToken );
	} catch (Exception e) {
		throw new RestClientException("Failed to login for user name:" + this.userName, e);
	}
	return securityToken;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:18,代码来源:IdServiceRestClientImpl.java


示例10: isTokenValid

import us.monoid.json.JSONObject; //导入依赖的package包/类
private boolean isTokenValid(String token) {
	if (token == null) {
		return false;
	}
	boolean isValid = false;
	try {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put(TOKEN, token);
		JSONResource response = resty.json(urlHelper.getTokenAuthenticationUrl(), RestyHelper.content(jsonObject,APPLICATION_JSON));
		if (response != null) {
			if (HttpStatus.SC_OK == (response.getHTTPStatus())) {
				isValid = true;
			} else {
				LOGGER.info("Inavlid token with failure reason from id server:" + response.get(MESSAGE));
			}
		}
	} catch (Exception e) {
		LOGGER.error("Failed to valid token:" + token, e);
	}
	return isValid;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:22,代码来源:IdServiceRestClientImpl.java


示例11: logOut

import us.monoid.json.JSONObject; //导入依赖的package包/类
@Override
public void logOut() throws RestClientException {
	currentSessions.getAndDecrement();
	synchronized (LOCK) {
		if (token != null) {
			LOGGER.info("Total current sessions:" + currentSessions.get());
			if (currentSessions.get() == 0) {
				try {
					JSONObject jsonObject = new JSONObject();
					jsonObject.put(TOKEN, token);
					resty.json(urlHelper.getLogoutUrl(), RestyHelper.content((jsonObject)));
					LOGGER.info("Id service rest client logs out successfully with token:" + token );
					token = null;
				} catch (Exception e) {
					throw new RestClientException("Failed to login out " + this.userName, e);
				}
			}
		}
	}
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:21,代码来源:IdServiceRestClientImpl.java


示例12: login

import us.monoid.json.JSONObject; //导入依赖的package包/类
public boolean login()
{
	try
	{
		URL url = new URL(HOMEWIZARD_LOGIN_URL);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.setRequestMethod("GET");
		connection.setRequestProperty("Authorization", cloudAuth);
		connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
		connection.connect();
		
		BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
		StringBuilder buffer = new StringBuilder();
		String line;
		
		while((line = br.readLine()) != null)
		{
			buffer.append(line).append("\n");
		}			
		br.close();
		
		// Get session id from result JSON
		JSONObject json = new JSONObject(buffer.toString());
		cloudSessionId = json.get("session").toString();
	}
	catch(IOException | JSONException e)
	{
		log.warn("Error while login to cloud service ", e);
		return false;
	}
	
	return true;
}
 
开发者ID:bwssytems,项目名称:ha-bridge,代码行数:34,代码来源:HomeWizzardSmartPlugInfo.java


示例13: loadFromJSON

import us.monoid.json.JSONObject; //导入依赖的package包/类
public static OnlineGame loadFromJSON(JSONObject object) throws JSONException {
    return new OnlineGame(
            object.getInt("id"),
            RageGoServer.getPlayer(object.getInt("whites_id")),
            RageGoServer.getPlayer(object.getInt("blacks_id"))
    );
}
 
开发者ID:RageGo,项目名称:RageGo,代码行数:8,代码来源:OnlineGame.java


示例14: nextLink

import us.monoid.json.JSONObject; //导入依赖的package包/类
/**
 * 
 * @return the JSONObject for the next link under the _links, or null if not found
 */
protected JSONObject nextLink() {
    try {
        JSONObject links = (JSONObject)response.getJSONValue("_links");
        return (JSONObject)links.get("next");
    } catch (JSONException e) {
        // a JSONException is thrown if not found
    }
    return null;
}
 
开发者ID:Clarify,项目名称:clarify-java,代码行数:14,代码来源:ClarifyPaginatedModel.java


示例15: waitForTaskToFinish

import us.monoid.json.JSONObject; //导入依赖的package包/类
public JSONObject waitForTaskToFinish(String node, String taskId) throws IOException, LoginException, JSONException {
    JSONObject lastTaskStatus = null;
    Boolean isRunning = true;
    while (isRunning) {
        lastTaskStatus = getTaskStatus(node, taskId);
        isRunning = (lastTaskStatus.getString("status").equals("running"));
    }
    return lastTaskStatus;
}
 
开发者ID:justnom,项目名称:proxmox-plugin,代码行数:10,代码来源:Connector.java


示例16: getQemuMachines

import us.monoid.json.JSONObject; //导入依赖的package包/类
public HashMap<String, Integer> getQemuMachines(String node) throws IOException, LoginException, JSONException {
    HashMap<String, Integer> res = new HashMap<String, Integer>();
    JSONArray qemuVMs = getJSONResource("nodes/" + node + "/qemu").toObject().getJSONArray("data");
    for (int i = 0; i < qemuVMs.length(); i++) {
        JSONObject vm = qemuVMs.getJSONObject(i);
        res.put(vm.getString("name"), vm.getInt("vmid"));
    }
    return res;
}
 
开发者ID:justnom,项目名称:proxmox-plugin,代码行数:10,代码来源:Connector.java


示例17: getOrCreateSctId

import us.monoid.json.JSONObject; //导入依赖的package包/类
@Override
public Long getOrCreateSctId(UUID componentUuid, Integer namespaceId, String partitionId, String comment) throws RestClientException {
	Long result = null;
	int attempt = 1;
	while (result == null) {
			try {
				JSONObject requestData = new JSONObject();
				requestData.put(NAMESPACE, namespaceId.intValue());
				requestData.put(PARTITION_ID, partitionId);
				requestData.put(SYSTEM_ID, componentUuid.toString());
				requestData.put(SOFTWARE, SRS);
				requestData.put(GENERATE_LEGACY_IDS, "false");
				requestData.put(COMMENT, comment);
				JSONResource response = resty.json(urlHelper.getSctIdGenerateUrl(token), RestyHelper.content((requestData),APPLICATION_JSON));
				if ( response != null && HttpStatus.SC_OK == (response.getHTTPStatus()) ){
					 result = new Long((String)response.get(SCTID));
				} else {
					throw new RestClientException(getFailureMessage(response));
				}
			} catch (Exception e) {
				
				if (attempt < maxTries) {
					LOGGER.warn("Id service failed on attempt {}. Waiting {} seconds before retrying.", attempt, retryDelaySeconds, e);
					attempt++;
					try {
						Thread.sleep(retryDelaySeconds * 1000);
					} catch (InterruptedException ie) {
						LOGGER.warn("Retry dealy interrupted.",e);
					}
				} else {
					throw new RestClientException("Failed to create sctId for uuid:" + componentUuid.toString(), e);
				}
			}
	}
	
	return result;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:38,代码来源:IdServiceRestClientImpl.java


示例18: getSctIdRecords

import us.monoid.json.JSONObject; //导入依赖的package包/类
public Map<Long,JSONObject> getSctIdRecords(Collection<Long> sctIds) throws RestClientException {
	Map<Long,JSONObject> result = new HashMap<>();
	if (sctIds == null || sctIds.isEmpty()) {
		return result;
	}
	int attempt = 1;
	boolean isDone = false;
	while (!isDone) {
			JSONResource response = null;
			try {
				response = resty.json(urlHelper.getSctIdBulkUrl(token, sctIds));
				if ( response != null && HttpStatus.SC_OK == (response.getHTTPStatus()) ){
					JSONArray items = response.array();
					for (int i =0;i < items.length();i++) {
						result.put(new Long((String)items.getJSONObject(i).get(SCTID)), items.getJSONObject(i));
					}
				} else {
					String errorMsg = (response != null) ? "http status code is:" + response.getHTTPStatus() : "No response received.";
					throw new RestClientException(errorMsg);
				}
				isDone = true;
			} catch (Exception e) {
				if (attempt < maxTries) {
					LOGGER.warn("Id service failed on attempt {}. Waiting {} seconds before retrying.", attempt, retryDelaySeconds, e);
					attempt++;
					try {
						Thread.sleep(retryDelaySeconds * 1000);
					} catch (InterruptedException ie) {
						LOGGER.warn("Retry delay interrupted.",e);
					}
				} else {
					throw new RestClientException("Failed to get sctIds for batch size:" + sctIds.size(), e);
				}
			}
	}
	return result;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:38,代码来源:IdServiceRestClientImpl.java


示例19: getSchemeIds

import us.monoid.json.JSONObject; //导入依赖的package包/类
public Map<String, JSONObject> getSchemeIds(SchemeIdType schemeType, Collection<String> legacyIds) throws RestClientException {
	Map<String,JSONObject> result = new HashMap<>();
	if (legacyIds == null || legacyIds.isEmpty()) {
		return result;
	}
	int attempt = 1;
	boolean isDone = false;
	while (!isDone) {
			JSONResource response = null;
			try {
				response = resty.json(urlHelper.getSchemeIdBulkUrl(token, schemeType, legacyIds));
				if ( response != null && HttpStatus.SC_OK == (response.getHTTPStatus()) ){
					JSONArray items = response.array();
					for (int i =0;i < items.length();i++) {
						result.put((String)items.getJSONObject(i).get(SCHEME_ID), items.getJSONObject(i));
					}
				} else {
					throw new RestClientException("http status code is:" + response.getHTTPStatus());
				}
				isDone = true;
			} catch (Exception e) {
				
				if (attempt < maxTries) {
					LOGGER.warn("Id service failed on attempt {}. Waiting {} seconds before retrying.", attempt, retryDelaySeconds, e);
					attempt++;
					try {
						Thread.sleep(retryDelaySeconds * 1000);
					} catch (InterruptedException ie) {
						LOGGER.warn("Retry delay interrupted.",e);
					}
				} else {
					throw new RestClientException("Failed to get sctIds for batch size:" + legacyIds.size(), e);
				}
			}
	}
	return result;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:38,代码来源:IdServiceRestClientImpl.java


示例20: getUuidsForSctIds

import us.monoid.json.JSONObject; //导入依赖的package包/类
@Override
public Map<Long, UUID> getUuidsForSctIds(Collection<Long> sctIds) throws RestClientException {
	Map<Long, UUID> sctIdUuidMap = new HashMap<>();
	List<Long> batchJob = null;
	int counter=0;
	for (Long sctId : sctIds) {
		if (batchJob == null) {
			batchJob = new ArrayList<>();
		}
		batchJob.add(sctId);
		counter++;
		if (counter % batchSize == 0 || counter == sctIds.size()) {
			Map<Long,JSONObject> sctIdRecords = getSctIdRecords(batchJob);
			String uuidStr = "";
			String jsonStr = "";
			for (Long id : sctIdRecords.keySet()) {
				try {
					jsonStr = sctIdRecords.get(id).toString();
					uuidStr = (String)sctIdRecords.get(id).get(SYSTEM_ID);
					sctIdUuidMap.put(id, UUID.fromString(uuidStr));
				} catch (IllegalArgumentException|JSONException e) {
					throw new RestClientException("Error when fetching system id for sctId: " + id + " using UUID '" + uuidStr + "'.  Received JSON: " + jsonStr, e);
				}
			}
			batchJob = null;
		}
	}
	return sctIdUuidMap;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:30,代码来源:IdServiceRestClientImpl.java



注:本文中的us.monoid.json.JSONObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClientResponseObserver类代码示例发布时间:2022-05-22
下一篇:
Java NioX509KeyManager类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap