List of usage examples for org.json.simple JSONObject toString
@Override
public String toString()
From source file:com.punyal.medusaserver.californiumServer.core.MedusaValidation.java
public static Client check(String medusaServerAddress, String myTicket, String ticket) { CoapClient coapClient = new CoapClient(); Logger.getLogger("org.eclipse.californium.core.network.CoAPEndpoint").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.EndpointManager").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.stack.ReliabilityLayer").setLevel(Level.OFF); CoapResponse response;//from ww w . java 2s.c o m coapClient.setURI(medusaServerAddress + "/" + MEDUSA_SERVER_VALIDATION_SERVICE_NAME); JSONObject json = new JSONObject(); json.put(JSON_MY_TICKET, myTicket); json.put(JSON_TICKET, ticket); response = coapClient.put(json.toString(), 0); if (response != null) { //System.out.println(response.getResponseText()); try { json.clear(); json = (JSONObject) JSONValue.parse(response.getResponseText()); long expireTime = (Long) json.get(JSON_TIME_TO_EXPIRE) + (new Date()).getTime(); String userName = json.get(JSON_USER_NAME).toString(); String[] temp = json.get(JSON_ADDRESS).toString().split("/"); String address; if (temp[1] != null) address = temp[1]; else address = "0.0.0.0"; Client client = new Client(InetAddress.getByName(address), userName, null, UnitConversion.hexStringToByteArray(ticket), expireTime); return client; } catch (Exception e) { } } else { // TODO: take } return null; }
From source file:com.dubture.symfony.core.util.JsonUtils.java
@SuppressWarnings("unchecked") public static String createScalar(String elementName, String viewPath, String method) { JSONObject data = new JSONObject(); data.put("elementName", elementName); data.put("viewPath", viewPath); data.put("method", method); JSONObject header = new JSONObject(); header.put("type", "scalar"); header.put("data", data); return header.toString(); }
From source file:com.dubture.symfony.core.util.JsonUtils.java
@SuppressWarnings("unchecked") public static String createReference(String elementName, String qualifier, String viewPath, String method) { JSONObject data = new JSONObject(); data.put("elementName", elementName); data.put("qualifier", qualifier); data.put("viewPath", viewPath); data.put("method", method); JSONObject header = new JSONObject(); header.put("type", "reference"); header.put("data", data); return header.toString(); }
From source file:com.p000ison.dev.copybooks.util.Helper.java
public static String fromListToJSONString(String key, List<String> list) { JSONObject json = new JSONObject(); JSONArray array = new JSONArray(); array.addAll(list);// ww w . j ava 2 s . c o m json.put(key, array); return json.toString(); }
From source file:com.fujitsu.dc.test.utils.RelationUtils.java
/** * Relation??.//from w w w . j a va2 s . c om * @param cellName ?? * @param token * @param body Body * @param code ? * @return ? */ public static TResponse create(final String cellName, final String token, final JSONObject body, int code) { TResponse response = Http.request("relation-create.txt").with("token", "Bearer " + token) .with("cellPath", cellName).with("body", body.toString()).returns().statusCode(code); return response; }
From source file:ly.stealth.punxsutawney.Marathon.java
private static JSONObject sendRequest(String uri, String method, JSONObject json) throws IOException { URL url = new URL(Marathon.url + uri); HttpURLConnection c = (HttpURLConnection) url.openConnection(); try {/*from ww w . ja v a 2 s. c o m*/ c.setRequestMethod(method); if (method.equalsIgnoreCase("POST")) { byte[] body = json.toString().getBytes("utf-8"); c.setDoOutput(true); c.setRequestProperty("Content-Type", "application/json"); c.setRequestProperty("Content-Length", "" + body.length); c.getOutputStream().write(body); } return (JSONObject) JSONValue.parse(new InputStreamReader(c.getInputStream(), "utf-8")); } catch (IOException e) { if (c.getResponseCode() == 404 && method.equals("GET")) return null; ByteArrayOutputStream response = new ByteArrayOutputStream(); InputStream err = c.getErrorStream(); if (err == null) throw e; Util.copyAndClose(err, response); IOException ne = new IOException(e.getMessage() + ": " + response.toString("utf-8")); ne.setStackTrace(e.getStackTrace()); throw ne; } finally { c.disconnect(); } }
From source file:autoancillarieslimited.parser.ParserUtil.java
public static String parserItemJSon(Item item) { JSONObject jSONObject = new JSONObject(); jSONObject.put("P0", item.getId()); jSONObject.put("P1", item.getName()); jSONObject.put("P3", item.getDescription()); jSONObject.put("P2", item.getTypeItem().getId()); jSONObject.put("P4", item.getPrice()); jSONObject.put("P6", item.getImages()); return jSONObject.toString(); }
From source file:com.fujitsu.dc.test.utils.RelationUtils.java
/** * Relation??(Basic?).//from w ww . j a v a 2 s .co m * @param cellName ?? * @param accountName Basic???Account?? * @param password Basic??? * @param body Body * @param code ? * @return ? */ public static TResponse createWithBasic(final String cellName, final String accountName, final String password, final JSONObject body, int code) { String credentials = Base64.encodeBase64String((accountName + ":" + password).getBytes()); TResponse response = Http.request("relation-create.txt").with("token", "Basic " + credentials) .with("cellPath", cellName).with("body", body.toString()).returns().statusCode(code); return response; }
From source file:com.aerothai.database.accessory.AccessoryService.java
/** * Method to construct JSON with Error Msg * * @param tag// w ww .j a v a 2s . c o m * @param status * @param err_msg * @return */ public static String constructJSON(String tag, boolean status, String msg) { JSONObject obj = new JSONObject(); obj.put("tag", tag); obj.put("status", new Boolean(status)); obj.put("msg", msg); return obj.toString(); }
From source file:RemoteDeviceDiscovery.java
public static String deviceJson(RemoteDevice d) { String address = d.getBluetoothAddress(); address = address.substring(0, 10) + ":" + address.substring(10, address.length()); address = address.substring(0, 8) + ":" + address.substring(8, address.length()); address = address.substring(0, 6) + ":" + address.substring(6, address.length()); address = address.substring(0, 4) + ":" + address.substring(4, address.length()); address = address.substring(0, 2) + ":" + address.substring(2, address.length()); String name = ""; try {// ww w. ja v a2s . c om name = d.getFriendlyName(false); } catch (IOException e) { try { name = d.getFriendlyName(false); } catch (IOException e2) { } } JSONObject obj = new JSONObject(); obj.put("clientVersion", "1.0"); obj.put("clientType", "bluecat"); obj.put("timestamp", new Date().getTime()); obj.put("bluetoothAddress", address); obj.put("bluetoothName", name); return obj.toString(); }