本文整理汇总了Java中us.monoid.json.JSONException类的典型用法代码示例。如果您正苦于以下问题:Java JSONException类的具体用法?Java JSONException怎么用?Java JSONException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSONException类属于us.monoid.json包,在下文中一共展示了JSONException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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.");
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
}
}
示例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;
}
示例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"))
);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}