List of usage examples for org.json.simple JSONObject containsKey
boolean containsKey(Object key);
From source file:org.daxplore.presenter.server.storage.QuestionMetadataServerImpl.java
/** * {@inheritDoc}//w w w . j a v a2 s. co m */ @Override public boolean hasSecondary(String column) { JSONObject question = getQuestion(column); return question.containsKey("hasOld") && (Boolean) question.get("hasOld"); }
From source file:org.daxplore.presenter.server.storage.QuestionMetadataServerImpl.java
/** * {@inheritDoc}/* w w w .jav a 2s . com*/ */ @Override public boolean hasMean(String column) { JSONObject question = getQuestion(column); return question.containsKey("hasMean") && (Boolean) question.get("hasMean"); }
From source file:org.disit.servicemap.test.ServiceMapApiTest.java
static private Object jsonPath(JSONObject o, String[] path, int start) { if (o.containsKey(path[start])) { if (start + 1 < path.length) { Object x = o.get(path[start]); if (x instanceof JSONObject) return jsonPath((JSONObject) x, path, start + 1); else if (x instanceof JSONArray) return jsonPath((JSONArray) x, path, start + 1); }/*from ww w . ja va2 s . c o m*/ return o.get(path[start]); } return null; }
From source file:org.dragonet.net.translator.protocols.v0_10_0.Translator_v0_10_0.java
public String translateChatMessage(JSONObject jsonObj) { StringBuilder sbuilder = new StringBuilder( jsonObj.containsKey("text") ? ((String) jsonObj.get("text")) : ""); if (jsonObj.containsKey("extra")) { if (jsonObj.get("extra") instanceof LinkedList) { LinkedList<JSONObject> jsonList = (LinkedList<JSONObject>) jsonObj.get("extra"); for (JSONObject obj : jsonList) { if (obj.containsKey("text")) { sbuilder.append((String) obj.get("text")); }//from ww w.jav a2 s .c om } } else if (jsonObj.get("extra") instanceof JSONArray) { JSONArray jsonArray = (JSONArray) jsonObj.get("extra"); if (jsonArray.size() > 0) { for (int i = 0; i < jsonArray.size(); i++) { if (((JSONObject) jsonArray.get(i)).containsKey("text")) { sbuilder.append((String) ((JSONObject) jsonArray.get(i)).get("text")); } } } } } return sbuilder.toString(); }
From source file:org.dragonet.net.translator.Translator_v0_11.java
public String translateChatMessage(JSONObject jsonObj) { StringBuilder sbuilder = new StringBuilder(); if (jsonObj.containsKey("text")) { if (jsonObj.containsKey("color")) { try { sbuilder.append(MCColor.valueOf((String) jsonObj.get("color")).getPECode().toUpperCase()); } catch (IllegalArgumentException e) { }/*from ww w . ja va 2 s . c om*/ } sbuilder.append(((String) jsonObj.get("text"))); } if (jsonObj.containsKey("extra")) { if (jsonObj.get("extra") instanceof LinkedList) { LinkedList<JSONObject> jsonList = (LinkedList<JSONObject>) jsonObj.get("extra"); for (JSONObject obj : jsonList) { if (obj.containsKey("text")) { if (obj.containsKey("color")) { try { sbuilder.append( MCColor.valueOf((String) obj.get("color")).getPECode().toUpperCase()); } catch (IllegalArgumentException e) { } } sbuilder.append((String) obj.get("text")); } } } else if (jsonObj.get("extra") instanceof JSONArray) { JSONArray jsonArray = (JSONArray) jsonObj.get("extra"); if (jsonArray.size() > 0) { for (Iterator it = jsonArray.iterator(); it.hasNext();) { Object obj = it.next(); if (((JSONObject) obj).containsKey("text")) { if (((JSONObject) obj).containsKey("color")) { try { sbuilder.append(MCColor.valueOf((String) ((JSONObject) obj).get("color")) .getPECode().toUpperCase()); } catch (IllegalArgumentException e) { } } sbuilder.append((String) ((JSONObject) obj).get("text")); } } } } } return sbuilder.toString(); }
From source file:org.eclairjs.nashorn.wrap.sql.SparkSession.java
static Row jsonToRow(org.json.simple.JSONObject json, List<Tuple2<String, DataType>> fieldsNames) { List<Object> values = new ArrayList<>(); ////from w w w . j ava2 s. c om // code for it is an object, but that is probably not possible // ScriptObjectMirror json=ScriptUtils.wrap((jdk.nashorn.internal.runtime.ScriptObject) obj); // // for (String name : fieldsNames) // { // Object value = null; // if (json.containsKey(name)) // { // value=json.get(name); // // if it is getter function, call to get value // if (value instanceof ScriptObjectMirror) // { // value=((ScriptObjectMirror)value).call(json); // } // // } // else // { // name="get" + name.substring(0,1).toUpperCase() + name.substring(1); // value=json.get(name); // // if it is getter function, call to get value // if (value instanceof ScriptObjectMirror) // { // value=((ScriptObjectMirror)value).call(json); // } // } // values.add(value); // } for (Tuple2<String, DataType> tuple : fieldsNames) { Object value = null; String name = tuple._1(); if (json.containsKey(name)) { value = json.get(name); // if it is getter function, call to get value value = castDataType(value, tuple._2()); } values.add(value); } return RowFactory.create(values.toArray()); }
From source file:org.eclipse.cdt.boost.build.core.internal.model.Response.java
private Response(String response) { JSONObject responseObj = (JSONObject) JSONValue.parse(response); if ("response".equals(responseObj.get("type"))) { if (responseObj.containsKey("response")) { Object r = responseObj.get("response"); if (r instanceof List) { fResponse = (List<Map<String, Object>>) responseObj.get("response"); } else { fResponse = new ArrayList<Map<String, Object>>(); fResponse.add((Map<String, Object>) r); }/* w w w. ja v a2s . c o m*/ } } }
From source file:org.eclipse.paho.android.service.sample.JSONFormatController.java
public static String[] readJSONmessage(String JSON) { String[] messg = new String[3]; try {//from ww w . j a v a 2 s .co m // System.out.println("Decoding :"+ JSON); JSONObject jsonObject = (JSONObject) (new JSONParser().parse(JSON)); String text = (String) jsonObject.get("text"); String owner = (String) jsonObject.get("owner"); messg[0] = text; messg[1] = owner; if (jsonObject.containsKey("corre-id")) messg[2] = (String) jsonObject.get("corre-id"); else messg[2] = "corre-id"; // System.out.println(messg); } catch (ParseException e) { // messg[0] = JSON; messg[1] = null; if (JSON.contains(",")) { String[] str = JSON.split(","); if (str[1].contains("\"text\":")) { String[] temp = str[1].split(":"); messg[0] = temp[1].substring(1, temp[1].length() - 2); } else { messg[0] = JSON; messg[1] = null; } } // e.printStackTrace(); } catch (Exception e) { messg[0] = JSON; messg[1] = null; if (JSON.contains(",")) { String[] str = JSON.split(","); if (str[1].contains("\"text\":")) { String[] temp = str[1].split(":"); messg[0] = temp[1].substring(1, temp[1].length() - 2); } else { messg[0] = JSON; messg[1] = null; } } // e.printStackTrace(); } return messg; }
From source file:org.exoplatform.utils.ExoConnectionUtils.java
public static boolean checkPLFVersion(HttpResponse response, String domain, String username) { try {/*from ww w . java2 s. co m*/ String result = getPLFStream(response); JSONObject json = (JSONObject) JSONValue.parse(result); String isCompliant = json.get(ExoConstants.IS_MOBILE_COMPLIANT).toString(); if ("true".equalsIgnoreCase(isCompliant)) { String editionObject = json.get(ExoConstants.PLATFORM_EDITION).toString(); ServerSettingHelper.getInstance().setServerEdition(editionObject); String verObject = json.get(ExoConstants.PLATFORM_VERSION).toString(); ServerSettingHelper.getInstance().setServerVersion(verObject); /* * Get repository name */ String repository = ExoConstants.DOCUMENT_REPOSITORY; if (json.containsKey(ExoConstants.PLATFORM_CURRENT_REPO_NAME)) { repository = json.get(ExoConstants.PLATFORM_CURRENT_REPO_NAME).toString(); if (repository == null || "".equals(repository.trim())) { repository = ExoConstants.DOCUMENT_REPOSITORY; } } DocumentHelper.getInstance().repository = repository; /* * Get default workspace name */ String workspace = ExoConstants.DOCUMENT_COLLABORATION; if (json.containsKey(ExoConstants.PLATFORM_DEFAULT_WORKSPACE)) { workspace = json.get(ExoConstants.PLATFORM_DEFAULT_WORKSPACE).toString(); if (workspace == null || "".equals(workspace.trim())) workspace = ExoConstants.DOCUMENT_COLLABORATION; } DocumentHelper.getInstance().workspace = workspace; String userHomeNode = json.get(ExoConstants.USER_HOME_NODE_PATH).toString(); ExoDocumentUtils.setRepositoryHomeUrl(username, userHomeNode, domain); return true; } else return false; } catch (RuntimeException e) { return false; } }
From source file:org.fragzone.unrealmmo.bukkit.entities.npcs.NPCProfile.java
private static void addProperties(GameProfile profile, UUID id) { String uuid = id.toString().replaceAll("-", ""); try {/*from w w w . j ava 2 s . c om*/ // Get the name from SwordPVP URL url = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid); URLConnection uc = url.openConnection(); uc.setUseCaches(false); uc.setDefaultUseCaches(false); uc.addRequestProperty("User-Agent", "Mozilla/5.0"); uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate"); uc.addRequestProperty("Pragma", "no-cache"); // Parse it Scanner scanner = new Scanner(uc.getInputStream(), "UTF-8"); String json = scanner.useDelimiter("\\A").next(); scanner.close(); JSONParser parser = new JSONParser(); Object obj = parser.parse(json); JSONArray properties = (JSONArray) ((JSONObject) obj).get("properties"); for (int i = 0; i < properties.size(); i++) { try { JSONObject property = (JSONObject) properties.get(i); String name = (String) property.get("name"); String value = (String) property.get("value"); String signature = property.containsKey("signature") ? (String) property.get("signature") : null; if (signature != null) { profile.getProperties().put(name, new Property(name, value, signature)); } else { profile.getProperties().put(name, new Property(value, name)); } } catch (Exception e) { Bukkit.getLogger().log(Level.WARNING, "Failed to apply auth property", e); } } } catch (Exception e) { e.printStackTrace(); } }