public static void main(String[] args) { // convert Java to json JSONObject root = new JSONObject(); root.put("message", "Hi"); JSONObject place = new JSONObject(); place.put("name", "World!"); root.put("place", place); String json = root.toJSONString(); System.out.println(json); System.out.println(); // convert json to Java JSONObject obj = (JSONObject) JSONValue.parse(json); String message = (String) obj.get("message"); place = (JSONObject) obj.get("place"); String name = (String) place.get("name"); System.out.println(message + " " + name); } }
json = (JSONArray) JSONValue.parse(new InputStreamReader(conn.getInputStream())); } catch (IOException e) { GlowServer.logger.warning("Couldn't get UUID due to IO error: " + e); String uuid = (String) ((JSONObject) json.get(0)).get("id"); return UuidUtils.fromFlatString(uuid);
protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.JMS_TOPIC_NAME); } else { handleError(conn); } return null; } }
protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.JMS_TOPIC_NAME); } else { handleError(conn); } return null; } }
public static String extractMethod(HttpServletRequest request) { InputStream in = null; try { in = request.getInputStream(); InputStreamReader reader = new InputStreamReader(in); JSONObject json = (JSONObject) JSONValue.parse(reader); return json.get("method").toString(); } catch (IOException e) { return null; } finally { IOUtils.closeQuietly(in); } }
@Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.JOB_ID); } else { handleError(conn); } return null; } }
public static String extractMethod(HttpServletRequest request) { InputStream in = null; try { in = request.getInputStream(); InputStreamReader reader = new InputStreamReader(in); JSONObject json = (JSONObject) JSONValue.parse(reader); return json.get("method").toString(); } catch (IOException e) { return null; } finally { IOUtils.closeQuietly(in); } }
private static JSONArray readJSONArray(String ar) { try { JSONObject json = (JSONObject) JSONValue.parse("{\"x\":" + ar + "}"); if (json == null) { throw new IllegalArgumentException("Could not parse json object " + ar + "."); } return (JSONArray) json.get("x"); } catch (ClassCastException e) { throw new IllegalArgumentException("Could not parse json object " + ar + "."); } }
@Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject jsonObject = (JSONObject) JSONValue.parse(reader); Object msg = jsonObject.get(JsonTags.PURGE); return msg.toString(); } else { handleError(conn); } return null; } }
@Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.STATUS); } else { handleError(conn); } return null; } }
public Product readItem(String id) throws Exception{ String content= jedis.get(id); if(content == null || ("nil".equals(content))) return null; Object obj=JSONValue.parse(content); JSONObject product=(JSONObject)obj; Product i= new Product((Long)product.get("id"), (String)product.get("title"), (Long)product.get("price"), (String)product.get("category")); return i; }
@Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return json.get(JsonTags.BUILD_INFO).toString(); } else { handleError(conn); } return null; } }
private JSONArray getModules() { String content = getContentApiFile(); if (content != null && !content.isEmpty()) { JSONObject root = (JSONObject) JSONValue.parse(content); if (root != null) { Object jsonValue = root.get(MODULES); if (jsonValue != null && jsonValue instanceof JSONArray) { return (JSONArray) jsonValue; } } } return null; }
@Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { Reader reader = new InputStreamReader(conn.getInputStream()); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.BUILD_VERSION); } else { handleError(conn); } return null; } }
@Override protected JSONObject call(HttpURLConnection conn) throws IOException, OozieClientException { conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); return (JSONObject) JSONValue.parse(reader); } else { handleError(conn); } return null; } }
private User setUserData(User user, String userString){ JSONObject userObj = (JSONObject) new JSONValue().parse(userString); user.setUsername((String) userObj.get("username")); user.setTenantDomain((String) userObj.get("tenantDomain")); user.setTenantId(Integer.valueOf(String.valueOf(userObj.get("tenantId")))); return user; }
@Override protected String call(HttpURLConnection conn) throws IOException, OozieClientException { if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK)) { Reader reader = new InputStreamReader(conn.getInputStream(), Charsets.UTF_8); JSONObject json = (JSONObject) JSONValue.parse(reader); return (String) json.get(JsonTags.JOB_ID); } else { handleError(conn); } return null; } }