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

Java JSONException类代码示例

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

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



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

示例1: getDevices

import us.monoid.json.JSONException; //导入依赖的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.JSONException; //导入依赖的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.JSONException; //导入依赖的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.JSONException; //导入依赖的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.JSONException; //导入依赖的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.JSONException; //导入依赖的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.JSONException; //导入依赖的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.JSONException; //导入依赖的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: login

import us.monoid.json.JSONException; //导入依赖的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


示例10: loadFromJSON

import us.monoid.json.JSONException; //导入依赖的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


示例11: handleException

import us.monoid.json.JSONException; //导入依赖的package包/类
public static RageGoServerException handleException(Exception e) {
    if(e instanceof IOException){
        return new RageGoServerException(RageGoServerException.ExceptionType.OFFLINE, e);
    }
    if(e instanceof JSONException){
        return new RageGoServerException(RageGoServerException.ExceptionType.DATA_MALFORMED, e);
    }
    return new RageGoServerException(RageGoServerException.ExceptionType.UNKNOWN, e);
}
 
开发者ID:RageGo,项目名称:RageGo,代码行数:10,代码来源:RageGoServer.java


示例12: cubesAdapterQuery

import us.monoid.json.JSONException; //导入依赖的package包/类
public List<Measurement> cubesAdapterQuery(String bindedSystem, String cubeName, String queryExpression) throws uQasarException{
	URI uri = null;
	LinkedList<Measurement> measurements = new LinkedList<>();

	try {
		uri = new URI(bindedSystem + "/" + queryExpression);
		String url = uri.toASCIIString();

		JSONResource res = getJSON(url);
		us.monoid.json.JSONObject json = res.toObject();
		logger.info(json.toString());

		JSONArray measurementResultJSONArray = new JSONArray();
		JSONObject bp = new JSONObject();
		bp.put("self", url);
		bp.put("key", cubeName);
		bp.put("name", queryExpression);
		measurementResultJSONArray.put(bp);
		logger.info(measurementResultJSONArray.toString());

		measurements.add(new Measurement(uQasarMetric.PROJECTS_PER_SYSTEM_INSTANCE, measurementResultJSONArray.toString()));

	} catch (URISyntaxException | org.apache.wicket.ajax.json.JSONException | JSONException | IOException e) {
		e.printStackTrace();
	}

       return measurements;
}
 
开发者ID:U-QASAR,项目名称:u-qasar.platform,代码行数:29,代码来源:CubesDataService.java


示例13: nextLink

import us.monoid.json.JSONException; //导入依赖的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


示例14: getNodes

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


示例15: waitForTaskToFinish

import us.monoid.json.JSONException; //导入依赖的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.JSONException; //导入依赖的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: getQemuMachineSnapshots

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


示例18: rollbackQemuMachineSnapshot

import us.monoid.json.JSONException; //导入依赖的package包/类
public String rollbackQemuMachineSnapshot(String node, Integer vmid, String snapshotName)
        throws IOException, LoginException, JSONException {
    Resty r = authedClient();
    String resource = "nodes/" + node + "/qemu/" + vmid.toString() + "/snapshot/" + snapshotName + "/rollback";
    JSONResource response = r.json(baseURL + resource, form(""));
    return response.toObject().getString("data");
}
 
开发者ID:justnom,项目名称:proxmox-plugin,代码行数:8,代码来源:Connector.java


示例19: getUuidsForSctIds

import us.monoid.json.JSONException; //导入依赖的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


示例20: getPlayerJSONObject

import us.monoid.json.JSONException; //导入依赖的package包/类
private static JSONObject getPlayerJSONObject(int id) throws IOException, JSONException {
    return getInstance().json(getPlayerURL(id)).object();
}
 
开发者ID:RageGo,项目名称:RageGo,代码行数:4,代码来源:RageGoServer.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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