List of usage examples for org.json JSONArray length
public int length()
From source file:com.sina.weibo.sdk_lib.openapi.models.OffsetGeo.java
public static OffsetGeo parse(String jsonString) { if (TextUtils.isEmpty(jsonString)) { return null; }/* www . j a v a 2s. c o m*/ OffsetGeo offsetGeo = new OffsetGeo(); try { JSONObject jsonObject = new JSONObject(jsonString); JSONArray jsonArray = jsonObject.optJSONArray("geos"); if (jsonArray != null && jsonArray.length() > 0) { int length = jsonArray.length(); offsetGeo.Geos = new ArrayList<Coordinate>(length); for (int ix = 0; ix < length; ix++) { offsetGeo.Geos.add(Coordinate.parse(jsonArray.optJSONObject(ix))); } } } catch (JSONException e) { e.printStackTrace(); } return offsetGeo; }
From source file:fr.pasteque.pos.sales.restaurant.JTicketsBagRestaurantMap.java
/** Creates new form JTicketsBagRestaurant */ public JTicketsBagRestaurantMap(AppView app, TicketsEditor panelticket) { super(app, panelticket); dlReceipts = new DataLogicReceipts(); dlSales = new DataLogicSales(); m_restaurantmap = new JTicketsBagRestaurant(app, this); m_PlaceCurrent = null;//from ww w .j a va 2 s . c om m_PlaceClipboard = null; customer = null; this.floors = new ArrayList<Floor>(); this.places = new HashMap<String, List<Place>>(); try { ServerLoader loader = new ServerLoader(); ServerLoader.Response r = loader.read("PlacesAPI", "getAll"); if (r.getStatus().equals(ServerLoader.Response.STATUS_OK)) { JSONArray a = r.getArrayContent(); for (int i = 0; i < a.length(); i++) { JSONObject oFloor = a.getJSONObject(i); Floor f = new Floor(oFloor); this.floors.add(f); this.places.put(f.getID(), new ArrayList<Place>()); JSONArray aPlaces = oFloor.getJSONArray("places"); for (int j = 0; j < aPlaces.length(); j++) { Place p = new Place(aPlaces.getJSONObject(j)); this.places.get(f.getID()).add(p); } } } } catch (Exception e) { e.printStackTrace(); } initComponents(); // add the Floors containers if (this.floors.size() > 1) { // A tab container for 2 or more floors JTabbedPane jTabFloors = new JTabbedPane(); jTabFloors.applyComponentOrientation(getComponentOrientation()); jTabFloors.setBorder(new javax.swing.border.EmptyBorder(new Insets(5, 5, 5, 5))); jTabFloors.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); jTabFloors.setFocusable(false); jTabFloors.setRequestFocusEnabled(false); m_jPanelMap.add(jTabFloors, BorderLayout.CENTER); for (Floor f : this.floors) { f.getContainer().applyComponentOrientation(getComponentOrientation()); JScrollPane jScrCont = new JScrollPane(); jScrCont.applyComponentOrientation(getComponentOrientation()); JPanel jPanCont = new JPanel(); jPanCont.applyComponentOrientation(getComponentOrientation()); jTabFloors.addTab(f.getName(), f.getIcon(), jScrCont); jScrCont.setViewportView(jPanCont); jPanCont.add(f.getContainer()); } } else if (this.floors.size() == 1) { // Just a frame for 1 floor Floor f = this.floors.get(0); f.getContainer().applyComponentOrientation(getComponentOrientation()); JPanel jPlaces = new JPanel(); jPlaces.applyComponentOrientation(getComponentOrientation()); jPlaces.setLayout(new BorderLayout()); jPlaces.setBorder(new javax.swing.border.CompoundBorder( new javax.swing.border.EmptyBorder(new Insets(5, 5, 5, 5)), new javax.swing.border.TitledBorder(f.getName()))); JScrollPane jScrCont = new JScrollPane(); jScrCont.applyComponentOrientation(getComponentOrientation()); JPanel jPanCont = new JPanel(); jPanCont.applyComponentOrientation(getComponentOrientation()); // jPlaces.setLayout(new FlowLayout()); m_jPanelMap.add(jPlaces, BorderLayout.CENTER); jPlaces.add(jScrCont, BorderLayout.CENTER); jScrCont.setViewportView(jPanCont); jPanCont.add(f.getContainer()); } // Add all the Table buttons. for (Floor f : this.floors) { List<Place> places = this.places.get(f.getID()); for (Place pl : places) { f.getContainer().add(pl.getButton()); pl.setButtonBounds(); pl.getButton().addActionListener(new MyActionListener(pl)); } } // Add the reservations panel m_jreservations = new JTicketsBagRestaurantRes(app, this); add(m_jreservations, "res"); }
From source file:org.wso2.emm.agent.services.ProcessMessage.java
private void messageExecute(String msg) { stillProcessing = true;//w ww. ja v a 2 s. c o m JSONArray repArray = new JSONArray(); JSONObject jsReply = null; String msgId = ""; JSONArray dataReply = null; try { JSONArray jArr = new JSONArray(msg.trim()); for (int i = 0; i < jArr.length(); i++) { JSONArray innerArr = new JSONArray(jArr.getJSONObject(i).getString("data")); String featureCode = jArr.getJSONObject(i).getString("code"); dataReply = new JSONArray(); jsReply = new JSONObject(); jsReply.put("code", featureCode); for (int x = 0; x < innerArr.length(); x++) { msgId = innerArr.getJSONObject(x).getString("messageId"); jsReply.put("messageId", msgId); if (featureCode.equals(CommonUtilities.OPERATION_POLICY_BUNDLE)) { SharedPreferences mainPrefp = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE); Editor editorp = mainPrefp.edit(); editorp.putString("policy", ""); editorp.commit(); SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE); Editor editor = mainPref.edit(); String arrToPut = innerArr.getJSONObject(0).getJSONArray("data").toString(); editor.putString("policy", arrToPut); editor.commit(); } String msgData = innerArr.getJSONObject(x).getString("data"); JSONObject dataObj = new JSONObject("{}"); operation = new Operation(context); if (featureCode.equalsIgnoreCase(CommonUtilities.OPERATION_POLICY_REVOKE)) { operation.operate(featureCode, jsReply); jsReply.put("status", msgId); } else { if (msgData.charAt(0) == '[') { JSONArray dataArr = new JSONArray(msgData); for (int a = 0; a < dataArr.length(); a++) { JSONObject innterDataObj = dataArr.getJSONObject(a); featureCode = innterDataObj.getString("code"); String dataTemp = innterDataObj.getString("data"); if (!dataTemp.isEmpty() && dataTemp != null && !dataTemp.equalsIgnoreCase("null")) dataObj = innterDataObj.getJSONObject("data"); dataReply = operation.operate(featureCode, dataObj); //dataReply.put(resultJson); } } else { if (!msgData.isEmpty() && msgData != null && !msgData.equalsIgnoreCase("null")) if (msgData.charAt(0) == '{') { dataObj = new JSONObject(msgData); } dataReply = operation.operate(featureCode, dataObj); //dataReply.put(resultJson); } } } jsReply.put("data", dataReply); repArray.put(jsReply); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (Operation.enterpriseWipe == false) { SharedPreferences mainPref = context.getSharedPreferences( context.getResources().getString(R.string.shared_pref_package), Context.MODE_PRIVATE); String regId = mainPref.getString(context.getResources().getString(R.string.shared_pref_regId), ""); PayloadParser ps = new PayloadParser(); replyPayload = ps.generateReply(repArray, regId); if (CommonUtilities.DEBUG_MODE_ENABLED) { Log.e(TAG, "replyPlayload -" + replyPayload); } stillProcessing = false; getOperations(replyPayload); } } }
From source file:com.esri.cordova.geolocation.AdvancedGeolocation.java
private void parseArgs(JSONArray args) { Log.d(TAG, "Execute args: " + args.toString()); if (args.length() > 0) { try {/* w w w . j a v a 2s.c om*/ final JSONObject obj = args.getJSONObject(0); _minTime = obj.getLong("minTime"); _minDistance = obj.getLong("minDistance"); _noWarn = obj.getBoolean("noWarn"); _providers = obj.getString("providers"); _useCache = obj.getBoolean("useCache"); _returnSatelliteData = obj.getBoolean("satelliteData"); _buffer = obj.getBoolean("buffer"); _signalStrength = obj.getBoolean("signalStrength"); _bufferSize = obj.getInt("bufferSize"); } catch (Exception exc) { Log.d(TAG, ErrorMessages.INCORRECT_CONFIG_ARGS + ", " + exc.getMessage()); sendCallback(PluginResult.Status.ERROR, ErrorMessages.INCORRECT_CONFIG_ARGS + ", " + exc.getMessage()); } } }
From source file:org.privatenotes.Note.java
public Note(JSONObject json) { // These methods return an empty string if the key is not found setTitle(XmlUtils.unescape(json.optString("title"))); setGuid(json.optString("guid")); setLastChangeDate(json.optString("last-change-date")); lastSyncRevision = json.optInt("last-sync-revision", -1); setXmlContent(json.optString("note-content")); JSONArray jtags = json.optJSONArray("tags"); String tag;/*from www . ja v a 2s . c o m*/ tags = new String(); if (jtags != null) { for (int i = 0; i < jtags.length(); i++) { tag = jtags.optString(i); tags += tag + ","; } } // encryption/decryption if (json.optString("encrypted") != null) { //<encrypted> setEncrypted(json.optString("encrypted").toLowerCase().trim().equals("true")); } //<encryptedAlgorithm> setEncryptedAlgorithm(json.optString("encryptedAlgorithm")); }
From source file:eu.codeplumbers.cosi.services.CosiFileService.java
private void getAllRemoteFiles() { URL urlO = null;//from www . j ava2 s. co m try { urlO = new URL(fileUrl); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoInput(true); conn.setRequestMethod("POST"); // read the response int status = conn.getResponseCode(); InputStream in = null; if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { in = conn.getErrorStream(); } else { in = conn.getInputStream(); } StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONArray jsonArray = new JSONArray(result); if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject fileJson = jsonArray.getJSONObject(i).getJSONObject("value"); File file = File.getByRemoteId(fileJson.get("_id").toString()); if (file == null) { file = new File(fileJson, false); } else { file.setName(fileJson.getString("name")); file.setPath(fileJson.getString("path")); file.setCreationDate(fileJson.getString("creationDate")); file.setLastModification(fileJson.getString("lastModification")); file.setTags(fileJson.getString("tags")); if (fileJson.has("binary")) { file.setBinary(fileJson.getJSONObject("binary").toString()); } file.setIsFile(true); file.setFileClass(fileJson.getString("class")); file.setMimeType(fileJson.getString("mime")); file.setSize(fileJson.getLong("size")); } mBuilder.setProgress(jsonArray.length(), i, false); mBuilder.setContentText("Indexing file : " + file.getName()); mNotifyManager.notify(notification_id, mBuilder.build()); EventBus.getDefault() .post(new FileSyncEvent(SYNC_MESSAGE, "Indexing file : " + file.getName())); file.setDownloaded(FileUtils.checkFileExists(Environment.getExternalStorageDirectory() + java.io.File.separator + Constants.APP_DIRECTORY + java.io.File.separator + "files" + file.getPath() + "/" + file.getName())); file.save(); allFiles.add(file); } } else { EventBus.getDefault() .post(new FileSyncEvent(SERVICE_ERROR, new JSONObject(result).getString("error"))); mNotifyManager.notify(notification_id, mBuilder.build()); stopSelf(); } in.close(); conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (ProtocolException e) { e.printStackTrace(); EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (IOException e) { e.printStackTrace(); EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (JSONException e) { e.printStackTrace(); EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } }
From source file:eu.codeplumbers.cosi.services.CosiFileService.java
private void getAllRemoteFolders() { //File.deleteAllFolders(); URL urlO = null;/*from w ww. j av a 2s . c o m*/ try { urlO = new URL(folderUrl); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoInput(true); conn.setRequestMethod("POST"); // read the response int status = conn.getResponseCode(); InputStream in = null; if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { in = conn.getErrorStream(); } else { in = conn.getInputStream(); } StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONArray jsonArray = new JSONArray(result); if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject folderJson = jsonArray.getJSONObject(i).getJSONObject("value"); File file = File.getByRemoteId(folderJson.get("_id").toString()); if (file == null) { file = new File(folderJson, true); } else { file.setName(folderJson.getString("name")); file.setPath(folderJson.getString("path")); file.setCreationDate(folderJson.getString("creationDate")); file.setLastModification(folderJson.getString("lastModification")); file.setTags(folderJson.getString("tags")); } mBuilder.setProgress(jsonArray.length(), i, false); mBuilder.setContentText("Indexing remote folder : " + file.getName()); mNotifyManager.notify(notification_id, mBuilder.build()); EventBus.getDefault() .post(new FileSyncEvent(SYNC_MESSAGE, "Indexing remote folder : " + file.getName())); file.save(); createFolder(file.getPath(), file.getName()); allFiles.add(file); } } else { EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, "Failed to parse API response")); stopSelf(); } in.close(); conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (ProtocolException e) { e.printStackTrace(); EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (IOException e) { e.printStackTrace(); EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (JSONException e) { e.printStackTrace(); EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } }
From source file:mr.robotto.engine.loader.components.mesh.MrMeshLoader.java
@Override public MrMesh parse() throws JSONException { int count = mRoot.getInt("Count"); String drawTypeData = mRoot.getString("DrawType"); String name = mRoot.getString("Name"); JSONArray vertexData = mRoot.getJSONArray("VertexData"); JSONArray indexData = mRoot.getJSONArray("IndexData"); JSONArray keysData = mRoot.getJSONArray("AttributeKeys"); int drawType = getDrawTypeFromString(drawTypeData); Map<Integer, MrBufferKey> keys = new HashMap<>(); //MrHashMap<Integer, MrBufferKey> keys = new MrHashMap<>(new MrMapFunction<Integer, MrBufferKey>() { // @Override // public Integer getKeyOf(MrBufferKey mrBufferKey) { // return mrBufferKey.getAttributeType(); // }// w w w. j a v a 2 s .c o m //}); //MrBuffer vertexBuffer = new MrVertexBuffer(vertexData.length()); //MrBuffer indexBuffer = new MrIndexBuffer(indexData.length()); MrBuffer vertexBuffer = MrBuffer.genVertexBuffer(vertexData.length()); MrBuffer indexBuffer = MrBuffer.genIndexBuffer(indexData.length()); loadVertexData(vertexBuffer, vertexData); loadIndexData(indexBuffer, indexData); loadKeys(keys, keysData); return new MrMesh(name, count, drawType, keys, vertexBuffer, indexBuffer); }
From source file:mr.robotto.engine.loader.components.mesh.MrMeshLoader.java
private void loadVertexData(MrBuffer buffer, JSONArray array) throws JSONException { for (int i = 0; i < array.length(); i++) { buffer.putFloat((float) array.getDouble(i)); }/* w w w. j a v a 2s .c o m*/ }
From source file:mr.robotto.engine.loader.components.mesh.MrMeshLoader.java
private void loadIndexData(MrBuffer buffer, JSONArray array) throws JSONException { for (int i = 0; i < array.length(); i++) { buffer.putShort((short) array.getInt(i)); }/* ww w . jav a2s. c o m*/ }