List of usage examples for org.json.simple.parser JSONParser JSONParser
JSONParser
From source file:org.uom.fit.level2.datavis.repository.ChatServicesImpl.java
@Override public JSONArray getAll() { try {/*w ww .java 2 s . c o m*/ Mongo mongo = new Mongo("localhost", 27017); DB db = mongo.getDB("datarepo"); DBCollection collection = db.getCollection("user"); DBCursor cursor = collection.find(); JSON json = new JSON(); String dataUser = json.serialize(cursor); JSONParser parser = new JSONParser(); Object obj = parser.parse(dataUser); JSONArray jsonarray = (JSONArray) obj; return jsonarray; } catch (Exception e) { System.out.println("Exception Error getAll"); return null; } }
From source file:org.exoplatform.social.client.core.util.SocialJSONDecodingSupport.java
/** * Parse JSON text into java Model object from the input source. * and then it's base on the class type. * //from ww w.j av a2 s .c o m * @param <T> Generic type must extend from Model. * @param clazz Class type. * @param jsonContent Json content which you need to create the Model * @throws ParseException Throw this exception if any * */ public static <T extends Model> T parser(final Class<T> clazz, String jsonContent) throws ParseException { JSONParser parser = new JSONParser(); ContainerFactory containerFactory = new ContainerFactory() { public List<T> creatArrayContainer() { return new LinkedList<T>(); } public T createObjectContainer() { try { return clazz.newInstance(); } catch (InstantiationException e) { return null; } catch (IllegalAccessException e) { return null; } } }; return (T) parser.parse(jsonContent, containerFactory); }
From source file:com.mp.gw2api.base.GW2APIDataList.java
@Override public void LoadFromJsonText(String text) { JSONParser parser = new JSONParser(); JSONObject json;/*from ww w . ja v a 2 s.co m*/ try { //Parse json array JSONArray ja = (JSONArray) parser.parse(text); //Create object array to retrieve data maps = new long[ja.size()]; if (ja != null) { for (int i = 0; i < ja.size(); i++) { maps[i] = (long) ja.get(i); } } } catch (ParseException ex) { Logger.getLogger(GW2APIDataList.class.getName()).log(Level.SEVERE, null, ex); maps = null; } }
From source file:it.avalz.opendaylight.controller.Network.java
/** * Parses the output string from the/*from w w w. j a va 2 s .co m*/ * /controller/nb/v2/switchmanager/default/nodes API * from the OpenDaylight controller and adds the resulting nodes to this * Network object. * * @param nodesString The JSON string result from the Controller API */ public void addNodesFromJSON(String nodesString) { JSONObject json = null; try { json = (JSONObject) new JSONParser().parse(nodesString); } catch (ParseException ex) { ex.printStackTrace(); } JSONArray nodes = (JSONArray) json.get("nodeProperties"); for (Object n : nodes) { JSONObject sw = (JSONObject) n; JSONObject node = (JSONObject) sw.get("node"); // TODO: Extract the Switch ports from the 'properties' object. JSONObject properties = (JSONObject) sw.get("properties"); String nodeId = (String) node.get("id"); this.addVertex(nodeId); } }
From source file:com.justgiving.raven.kissmetrics.schema.KissmetricsJsonToSchemaMapper.java
@Override public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String s = value.toString();// w w w . j a va 2 s . c o m JSONParser jsonParser = new JSONParser(); try { JSONObject jsonObject = (JSONObject) jsonParser.parse(s); Set<String> keyset = jsonObject.keySet(); String jsonValue = ""; for (String jsonkey : keyset) { jsonValue = (String) jsonObject.get(jsonkey).toString(); if (jsonValue == null || jsonValue == "") { jsonValue = ""; } String lenValue = String.valueOf(jsonValue.length()); if (lenValue == null || lenValue == "") { lenValue = "0"; } context.write(new Text(jsonkey), new Text("1\t" + lenValue)); } } catch (ParseException e) { e.printStackTrace(); } }
From source file:com.shazam.dataengineering.pipelinebuilder.DeploymentLog.java
public DeploymentLog(String json) { try {//from w w w . j a v a2 s .c om JSONParser jsonParser = new JSONParser(); log = (JSONObject) jsonParser.parse(json); } catch (ParseException e) { parseException = e; } }
From source file:controller.JsonController.java
public ArrayList<JsonModel> ReadJsonCalc() throws FileNotFoundException, IOException, ParseException { FileInputStream fstream = new FileInputStream("gistfile1.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine;//from w ww . j av a 2s .c o m ArrayList<JsonModel> result = new ArrayList<>(); JsonModel model; double L1, G1, L2, G2; //Read File Line By Line while ((strLine = br.readLine()) != null) { model = new JsonModel(); JSONParser parser = new JSONParser(); Object obj = parser.parse(strLine); JSONObject jsonObject = (JSONObject) obj; model.setLatitude((double) Double.parseDouble((String) jsonObject.get("latitude"))); model.setLongitude((double) Double.parseDouble((String) jsonObject.get("longitude"))); model.setUserIid((int) Integer.parseInt((String) jsonObject.get("user_id").toString())); model.setName(((String) jsonObject.get("name"))); L1 = Math.toRadians(model.getLatitudeDefault()); G1 = Math.toRadians(model.getLongitudeDefault()); L2 = Math.toRadians(model.getLatitude()); G2 = Math.toRadians(model.getLongitude()); // do the spherical trig calculation double angle = Math.acos(Math.sin(L1) * Math.sin(L2) + Math.cos(L1) * Math.cos(L2) * Math.cos(G1 - G2)); // convert back to degrees angle = Math.toDegrees(angle); // each degree on a great circle of Earth is 69.1105 miles double distance = (69.1105 * angle) * 1.609344; if (distance <= 100) result.add(model); } Collections.sort(result); return result; }
From source file:mikolaj.torrent.actions.Result.java
public JSONArray fromJsonArray(String data) { try {//from w ww . ja v a2s . c om JSONParser parser = new JSONParser(); Object obj = parser.parse(data); return (JSONArray) obj; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:com.asus.ctc.eebot.ie.externalresources.conceptnet.JsonDecoder.java
/** * /*from w w w .jav a 2 s. c om*/ */ public JsonDecoder() { parser = new JSONParser(); conceptVarEdgeMap = new HashMap<String, conceptNetEdgeVars>(); conceptVarMaps = new HashMap<String, conceptNetApiVars>(); initializeConceptNetVarMaps(); initializeconceptnetRelationMap(); }
From source file:com.appdynamics.cloudfoundry.appdservicebroker.CredentialsFactory.java
@Bean CredentialsHolder populateCredentialsHolder(@Value("${APPD_PLANS}") String appd_plans) throws ParseException { @SuppressWarnings("unchecked") HashMap<String, JSONObject> appd_plans_map = (JSONObject) new JSONParser().parse(appd_plans); return CredentialsHolder.createInstance(appd_plans_map); }