List of usage examples for org.json JSONObject getInt
public int getInt(String key) throws JSONException
From source file:util.Overview.java
public static void getSwitches(JSONArray Switches) throws JSONException, IOException, SQLException { /* /*from w ww . j a va2s.c o m*/ * LOGICA PARA SACAR LOS OBJETOS JSON DE CADA SWITCH CONECTADO * A FLOODLIGHT DE ACUERDO A LA LONGITUD DEL ARREGLO DE SWITCHES * SE SACAN EL NUMERO DE SWITCHES */ DBManager dbm = new DBManager(); for (int i = 0; i < Switches.length(); i++) { String dpid = null, inetAddress = null, software = null, hardware = null, manufacturer = null, serialNum = null, datapath = null; int connectedSince; JSONObject sw = Switches.getJSONObject(i); JSONObject description = sw.getJSONObject("description"); JSONArray ports = sw.getJSONArray("ports"); dpid = sw.getString("dpid"); inetAddress = sw.getString("inetAddress"); connectedSince = sw.getInt("connectedSince"); software = description.getString("software"); hardware = description.getString("hardware"); manufacturer = description.getString("manufacturer"); serialNum = description.getString("serialNum"); datapath = description.getString("datapath"); dbm.InsertSwitch(i, dpid, inetAddress, software, hardware, manufacturer, serialNum, datapath, connectedSince); for (int j = 0; j < ports.length(); j++) { int portNumber, state; String name = null, hardwareAddress = null; JSONObject port = ports.getJSONObject(j); name = port.getString("name"); hardwareAddress = port.getString("hardwareAddress"); portNumber = port.getInt("portNumber"); state = port.getInt("state"); dbm.InsertPort(j, i, portNumber, name, hardwareAddress, state); } } }
From source file:util.Overview.java
public static void getFlows(JSONObject Summary) throws JSONException, SQLException, IOException { /* //from w w w . j av a 2 s . c om * LOGICA PARA SACAR LA LISTA DE SWITCHES QUE CONTIENEN FLUJOS Y * LOS FLUJOS INSTALADOS EN CADA SWITCH Y SUS VARIABLES PARA * LA BASE DE DATOS */ JSONArray AS = Summary.names(); // Arreglo de Switches conectados for (int i = 0; i < Summary.length(); i++) { JSONObject s = Summary.getJSONObject(AS.getString(i)); // Se obtiene el JSONObject de los flujos que pertenece a cada switch JSONArray arr = s.names(); // Arreglo con los nombres de los flujos para ser recorrido for (int j = 0; j < s.length(); j++) { JSONObject t = s.getJSONObject(arr.getString(j)); // Se obtiene el JSONObject con los datos del flujo actual JSONObject match = t.getJSONObject("match"); // Se obtiene el JSONObject con los matchs del flujo actual int priority = t.getInt("priority"); // Se obtiene la prioridad del flujo actual int InputPort = match.getInt("inputPort"); // Se obtiene el inputPort del flujo actual JSONArray action = t.getJSONArray("actions"); // Se obtiene el JSONArray con los actions del flujo actual JSONObject actions = action.getJSONObject(0); // Se obtiene el JSONObject con el action del flujo actual int OutputPort = actions.getInt("port"); // Se obtiene el outputPort del flujo actual String accion = actions.getString("type"); // Se obtiene el tipo de la accion del flujo actual DBManager dbm = new DBManager(); String sname = arr.getString(j); int switchh = dbm.getIndex(AS.getString(i)); dbm.InsertFlow(j, i, sname, priority, InputPort, accion, OutputPort); } } }
From source file:util.Overview.java
public static void getPortStatistics(JSONObject PortSummary) throws JSONException { JSONArray PortNames;//from www . ja v a 2s.c o m PortNames = PortSummary.names(); for (int i = 0; i < PortSummary.length(); i++) { //se obtiene el arreglo que contiene las caracteristicas //del swich actual JSONArray pri = PortSummary.getJSONArray(PortNames.getString(i)); for (int j = 0; j < pri.length(); j++) { System.out.println("\n estadisticas generales del swich " + PortNames.getString(i)); //se obtiene el objeto JSON con las estadisticas de cada puerto JSONObject pre = pri.getJSONObject(j); int portNumber, receiveBytes, collisions, transmitBytes; int transmitPackets, receivePackets; portNumber = pre.getInt("portNumber"); receiveBytes = pre.getInt("receiveBytes"); collisions = pre.getInt("collisions"); transmitBytes = pre.getInt("transmitBytes"); transmitPackets = pre.getInt("transmitPackets"); receivePackets = pre.getInt("receivePackets"); // SE DEBE VERIFICAR UNA VARIABLE 'DATE' PARA ENVIAR A LA BASE DE DATOS Y QUE SEA EL EJE X DE UNA POSIBLE GRAFICA //DBManager dbm = new DBManager(); //String sname = arr.getString(j); //int switchh = dbm.getIndex(AS.getString(i)); //dbm.InsertPortStatistics(j,i,portNumber,receiveBytes,collisions,transmitBytes,transmitPackets,receivePackets); //System.out.println("portNumber: " + portNumber); //System.out.println("receiveBytes: " + receiveBytes); //System.out.println("collisions: " + collisions); //System.out.println("transmitBytes: " + transmitBytes); //System.out.println("transmitPackets: " + transmitPackets); //System.out.println("receivePackets: " + receivePackets); } } }
From source file:util.Overview.java
public static void getFlowStatistics(JSONObject FlowSummary) throws JSONException { JSONArray SFlowNames = FlowSummary.names(); //se obtiene el arreglo de equipos que tienen flujos activos for (int i = 0; i < SFlowNames.length(); i++) { //se obtienen las estadisticas de los flujos del switch actual JSONArray FlowStatistics = FlowSummary.getJSONArray(SFlowNames.getString(i)); for (int j = 0; j < FlowStatistics.length(); j++) { JSONObject FlowMatch;//from ww w. j a v a2 s.c om int packetCount, byteCount, FlowMatchPort, durationSeconds; //se obtiene las estadisticas del flujos actual JSONObject flow = FlowStatistics.getJSONObject(j); packetCount = flow.getInt("packetCount"); byteCount = flow.getInt("byteCount"); durationSeconds = flow.getInt("durationSeconds"); //las estadisticas floodlight las organiza de acuerdo a como //se instalaron //los flujos,asi mismo actualmente se determina a cual //flujo pertenece //usando los if. //CUANDO SE INSERTE TODO EN LA DB, ESTA PARTE NO SERA NECESARIA //PORQUE PARA SABER EL FLUJO AL QUE PERTENECE, SOLO SE HARIAN //COMPARACION DE LOS SELECTS DE LA TABLAS FLUJOS Y ESTADISTICAS //POR FLUJOS //COMPARANDO INPUTPORT,OUTPUTPORT Y LA ACCION A EJECUTAR //if(j==0) { // System.out.println("\n estadisticas especificas del " // + "flujo 1"); //} else { // System.out.println("\n estadisticas especificas del " // + "flujo 2"); //} System.out.println("Estadisticas especificas del flujo: " + j + "\n"); System.out.println("packetCount: " + packetCount); System.out.println("byteCount: " + byteCount); System.out.println("durationSeconds: " + durationSeconds); FlowMatch = flow.getJSONObject("match"); FlowMatchPort = FlowMatch.getInt("inputPort"); System.out.println("puerto de entrada: " + FlowMatchPort); JSONArray FlowActions; //se obtiene el arreglos de acciones que tiene el flujo actual FlowActions = flow.getJSONArray("actions"); int FlowOutport; String FlowType; JSONObject FActions; //se obtiene la accion correspondiente al flujo FActions = FlowActions.getJSONObject(0); FlowOutport = FActions.getInt("port"); FlowType = FActions.getString("type"); System.out.println("accion a ejecutar: " + FlowType); System.out.println("puerto de salida: " + FlowOutport + "\n"); } } }
From source file:de.dekarlab.moneybuilder.model.parser.JsonBookLoader.java
/** * Parse accounts.// w w w. j a va 2 s . c om * * @param jsonFolder * @param folder */ protected static void parseAccounts(JSONObject jsonFolder, Folder folder) { // add attributes to current folder. folder.setName(jsonFolder.getString("name")); parseAccountValues(jsonFolder, folder); // ---------------- JSONArray list = jsonFolder.getJSONArray("list"); for (int i = 0; i < list.length(); i++) { JSONObject jsonNewAccount = list.getJSONObject(i); if (jsonNewAccount.optString("folder").equals("y")) { Folder newFolder = new Folder(jsonNewAccount.getInt("type")); parseAccountValues(jsonNewAccount, newFolder); parseAccounts(jsonNewAccount, newFolder); folder.addAccount(newFolder); } else { Account newAccount = new Account(jsonNewAccount.getInt("type")); parseAccountValues(jsonNewAccount, newAccount); newAccount.setName(jsonNewAccount.getString("name")); if (jsonNewAccount.optString("hidden").equals("y")) { newAccount.setHidden(true); } String hiddenDate = jsonNewAccount.optString("hiddenDate"); if (hiddenDate != null) { newAccount.setHiddenDate(Formatter.parseDate(hiddenDate)); } folder.addAccount(newAccount); } } }
From source file:net.pixnet.sdk.response.Set.java
@Override protected JSONObject parseJSON(JSONObject jo) throws JSONException { jo = super.parseJSON(jo); if (jo.has("set")) jo = jo.getJSONObject("set"); if (jo.has("link")) link = jo.getString("link"); if (jo.has("permission")) permission = jo.getString("permission"); if (jo.has("category_id")) category_id = jo.getString("category_id"); if (jo.has("category")) category = jo.getString("category"); if (jo.has("is_lockright")) is_lockright = jo.getInt("is_lockright") == 0 ? false : true; if (jo.has("lincense")) licence = new License(jo.getJSONObject("lincense")); if (jo.has("cancomment")) cancomment = jo.getInt("cancomment") == 0 ? false : true; if (jo.has("parent_id")) parent_id = jo.getString("parent_id"); if (jo.has("is_system_set")) is_system_set = DataProxy.getJsonBoolean(jo, "is_system_set"); if (jo.has("hits")) hits = new Hits(jo.getJSONObject("hits")); if (jo.has("total_elements")) total_elements = jo.getInt("total_elements"); if (jo.has("is_taggable")) is_taggable = DataProxy.getJsonBoolean(jo, "is_taggable"); return jo;/* w ww. ja va 2s . co m*/ }
From source file:tech.salroid.filmy.tmdb_account.UnMarkingWatchList.java
private void parseMarkedResponse(JSONObject response) { if (listener != null) listener.unmarked(position);//from w w w . ja va 2 s .c o m try { int status_code = response.getInt("status_code"); if (status_code == 13) { CustomToast.show(context, "Movie removed from watchlist.", false); } else { CustomToast.show(context, "Can't remove from watchlist.", false); } } catch (JSONException e) { Log.d("webi", e.getCause().toString()); CustomToast.show(context, "Can't remove from watchlist.", false); } }
From source file:org.wso2.apim.billing.dao.ThrottleRequestDao.java
public InvoiceEntity GenerateInvoice(String planName, UserEntity user) { System.setProperty("javax.net.ssl.trustStore", jksPath); System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); if (planName == null) { planName = "silver"; }/*from ww w. j a v a 2s . c om*/ try { DASRestClient s = new DASRestClient(this.dasUrl, this.dasUserName, this.dasPassword.toCharArray()); String query = getQuery(planName);//"tenantDomain" + ":\"" + "admin@carbon.super" + "\""; if (query == null) { System.out.println("no subscription for plan: " + planName); return null; } //creating request bean SearchRequestBean request = new SearchRequestBean(query, 1, "tenantDomain_userId_facet", "THROTTLED_SUMMARY"); ArrayList<AggregateField> fields = new ArrayList<AggregateField>(); AggregateField field = new AggregateField("success_request_count", "sum", "sCount"); AggregateField field2 = new AggregateField("throttleout_count", "sum", "tCount"); fields.add(field); fields.add(field2); request.setAggregateFields(fields); CloseableHttpResponse res = s.doPost(request, this.dasUrl + DAS_AGGREGATES_SEARCH_REST_API_URL); String resMsg = getResponseBody(res); System.out.println("response: " + resMsg); JSONArray obj = new JSONArray(resMsg); JSONObject val = obj.getJSONObject(0).getJSONObject("values"); int sCount = val.getInt("sCount"); int tCount = val.getInt("tCount"); InvoiceEntity result = getInvoice(sCount, tCount, planName, user); return result; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java
private void addGeofence(CallbackContext callbackContext, JSONObject config) { try {// w w w .j a v a2 s. com String identifier = config.getString("identifier"); final Bundle event = new Bundle(); event.putString("name", BackgroundGeolocationService.ACTION_ADD_GEOFENCE); event.putBoolean("request", true); event.putFloat("radius", (float) config.getLong("radius")); event.putDouble("latitude", config.getDouble("latitude")); event.putDouble("longitude", config.getDouble("longitude")); event.putString("identifier", identifier); if (config.has("notifyOnEntry")) { event.putBoolean("notifyOnEntry", config.getBoolean("notifyOnEntry")); } if (config.has("notifyOnExit")) { event.putBoolean("notifyOnExit", config.getBoolean("notifyOnExit")); } if (config.has("notifyOnDwell")) { event.putBoolean("notifyOnDwell", config.getBoolean("notifyOnDwell")); } if (config.has("loiteringDelay")) { event.putInt("loiteringDelay", config.getInt("loiteringDelay")); } addGeofenceCallbacks.put(identifier, callbackContext); postEvent(event); } catch (JSONException e) { e.printStackTrace(); callbackContext.error(e.getMessage()); } }
From source file:com.dnastack.bob.rest.BasicTest.java
private static String readField(JSONObject field, List<String> path) { for (int i = 1; i < path.size(); i++) { field = field.getJSONObject(path.get(i - 1)); }//from w w w.j a v a2 s . c o m String loc = path.get(path.size() - 1); String res; try { res = field.getString(loc); } catch (JSONException je) { try { res = String.valueOf(field.getLong(loc)); } catch (JSONException je2) { try { res = String.valueOf(field.getInt(loc)); } catch (JSONException je3) { try { res = String.valueOf(field.getBoolean(loc)); } catch (JSONException je4) { res = null; } } } } return res; }