private void init(JSONArray jLogs) { logs = new ArrayList<>(); for (Object jLog1 : jLogs) { JSONObject jLog = (JSONObject) jLog1; byte[] address = Hex.decode((String) jLog.get("address")); byte[] data = Hex.decode(((String) jLog.get("data")).substring(2)); List<DataWord> topics = new ArrayList<>(); JSONArray jTopics = (JSONArray) jLog.get("topics"); for (Object t : jTopics.toArray()) { byte[] topic = Hex.decode(((String) t)); topics.add(DataWord.of(topic)); } LogInfo li = new LogInfo(address, topics, data); logs.add(li); } }
private static Collection<String> extractLabels(JSONObject issue) { Set<String> out = new HashSet<String>(); JSONArray labels = (JSONArray) issue.get("labels"); for (Object o : labels.toArray()) { JSONObject label = (JSONObject) o; out.add((String) label.get("name")); } return out; }
JSONObject resultsJSONObject = (JSONObject) JSONValue.parse(<<Fetched JSon String>>); JSONArray dataJSon = (JSONArray) resultsJSONObject.get("data"); JSONObject[] updates = dataJSon.toArray(new JSONObject[dataJSon.size()]); for (JSONObject update : updates) { String message_id = (String) update.get("message_id"); Integer author_id = (Integer) update.get("author_id"); Integer createdTime = (Integer) update.get("created_time"); //Do your own processing... //Here you can check null value or not.. }
public Values coerceResponce(JSONArray array){ return new Values(array.toArray()); }
public JsonObject findJsonObjectWithKey(String keyName) { Object[] reportCriteriaOptions = reportCriteriaOptionsJson.getArray( "results").toArray(); for (Object object : reportCriteriaOptions) { JsonObject jsonObject = (JsonObject) object; if (keyName.equals(jsonObject.get("key"))) { return jsonObject; } } return null; }
for (Object res : resources.toArray()) { JSONObject next = (JSONObject) res; String namedEntity = (String) next.get("namedEntity");
@POST @Path("removejobs") @RestQuery(name = "removejobs", description = "Removes all given jobs and their child jobs", returnDescription = "No data is returned, just the HTTP status code", restParameters = { @RestParameter(name = "jobIds", isRequired = true, description = "The IDs of the jobs to delete", type = Type.TEXT), }, reponses = { @RestResponse(responseCode = SC_NO_CONTENT, description = "Jobs successfully removed"), @RestResponse(responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR, description = "Error while removing jobs") }) public Response removeParentlessJobs(@FormParam("jobIds") String jobIds) throws NotFoundException { try { final JSONArray array = (JSONArray) JSONValue.parse(jobIds); final List<Long> jobIdList = Arrays.asList((Long[]) array.toArray(new Long[0])); serviceRegistry.removeJobs(jobIdList); return Response.noContent().build(); } catch (ServiceRegistryException e) { throw new WebApplicationException(e); } }
public Map<String, List<Entity>> getEntities(final String question) { HashMap<String, List<Entity>> tmp = new HashMap<>(); try { String JSONOutput = doTASK(question); JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(JSONOutput); JSONArray resources = (JSONArray) jsonObject.get("Resources"); if (resources != null) { ArrayList<Entity> tmpList = new ArrayList<>(); for (Object res : resources.toArray()) { JSONObject next = (JSONObject) res; Entity ent = new Entity(); ent.setOffset(Integer.valueOf((String) next.get("@offset"))); ent.setLabel((String) next.get("@surfaceForm")); String uri = ((String) next.get("@URI")).replaceAll(",", "%2C"); ent.getUris().add(new ResourceImpl(uri)); for (String type : ((String) next.get("@types")).split(",")) { ent.getPosTypesAndCategories().add(new ResourceImpl(type)); } tmpList.add(ent); } tmp.put("en", tmpList); } } catch (IOException | ParseException e) { log.error("Could not call Spotlight for NER/NED", e); } return tmp; }
@Override public Map<String, List<Entity>> getEntities(final String question) { HashMap<String, List<Entity>> tmp = new HashMap<>(); try { String foxJSONOutput = doTASK(question); JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(foxJSONOutput); JSONArray resources = (JSONArray) jsonObject.get("Resources"); if (resources != null) { ArrayList<Entity> tmpList = new ArrayList<>(); for (Object res : resources.toArray()) { JSONObject next = (JSONObject) res; Entity ent = new Entity(); ent.setOffset(Integer.valueOf((String) next.get("@offset"))); ent.setLabel((String) next.get("@surfaceForm")); String uri = ((String) next.get("@URI")).replaceAll(",", "%2C"); ent.getUris().add(new ResourceImpl(uri)); for (String type : ((String) next.get("@types")).split(",")) { ent.getPosTypesAndCategories().add(new ResourceImpl(type)); } tmpList.add(ent); } tmp.put("en", tmpList); } } catch (IOException | ParseException e) { log.error("Could not call Spotlight for NER/NED", e); } return tmp; }
if (responseString != null && !responseString.isEmpty()) { JSONArray jsonArray = (JSONArray) new JSONParser().parse(responseString); return (String[]) jsonArray.toArray(new String[jsonArray.size()]);
public void setConfig(JsonSimpleConfig config) throws IOException { // Get the basics file_path = config.getString(null, "roles", "internal", "path"); loadRoles(); JSONArray roleJsonArray = (JSONArray)config.getObject("roles", "internal").get("defaultRoles"); if(roleJsonArray != null) { defaultRoles = Arrays.copyOf(roleJsonArray.toArray(), roleJsonArray.size(), String[].class); } }
/** * Method to retrieve one of the definitions from the anyOf value from a schema node definition * * @param propertyObject the node from a schema which has a type of 'AnyOf' * @return Object random member definition of the one of the objects in the AnyOf json schema * field. */ private Object getOneOfAnyOf(JSONObject propertyObject) { Object[] array = ((JSONArray) propertyObject.get("anyOf")).toArray(); Validate.isTrue(array.length > 0); JSONObject nodeDef = (JSONObject) array[DataGenerator.generateRandomInt(0, array.length - 1)]; Object object = null;; try { object = generateNodeValue(null, null, nodeDef); } catch (ModelSearchException e) { e.printStackTrace(); } return object; }
for (Object res : resources.toArray()) { JSONObject next = (JSONObject) res; Entity ent = new Entity();
@SuppressWarnings("unchecked") private JSONArray skipNullResults(JSONArray source, String propertyName) { JSONArray result = new JSONArray(); for (Object item : source.toArray()) { if (((JSONObject) item).get(propertyName) == null) { continue; } result.add(item); } return result; } }
@SuppressWarnings("unchecked") private JSONArray skipNullResults(JSONArray source, String propertyName) { JSONArray result = new JSONArray(); for (Object item : source.toArray()) { if (((JSONObject) item).get(propertyName) == null) { continue; } result.add(item); } return result; } }
} else { JSONArray js = (JSONArray) val; map.put(key, js.toArray()); if (js.size() > 0) { Object o = js.get(0);
logger.log(Level.SEVERE, "A Parse exception was thrown", e); Object[] enumArray = enums.toArray(); String enumValue = enumArray[DataGenerator.generateRandomInt(0, enumArray.length - 1)].toString();
if (app.getPolicyPartials() != null && !app.getPolicyPartials().isEmpty()) { JSONArray policyPartialIdList = (JSONArray) JSONValue.parse(app.getPolicyPartials()); saveApplicationPolicyPartialsMappings(connection, webAppId, policyPartialIdList.toArray()); saveApplicationPolicyGroupsMappings(connection, webAppId, policyGroupIdList.toArray()); saveJavaPolicyMappings(connection, webAppId, javaPolicyIdList.toArray());