List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:com.nextgis.firereporter.ScanexSubscriptionItem.java
protected void FillData(int nType, String sData) { String sCleanData = GetFiresService.removeJsonT(sData); try {/*w w w. j a v a 2s .co m*/ JSONObject object = new JSONObject(sCleanData); String sStatus = object.getString("Status"); if (sStatus.equals("OK")) { JSONArray jsonArray = object.getJSONArray("Result"); for (int i = 0; i < jsonArray.length(); i++) { JSONArray jsonSubArray = jsonArray.getJSONArray(i); long nID = jsonSubArray.getLong(0); String sPtCoord = jsonSubArray.getString(1); int nConfidence = jsonSubArray.getInt(2); int nPower = jsonSubArray.getInt(3); String sURL1 = jsonSubArray.getString(4); String sURL2 = jsonSubArray.getString(5); String sType = jsonSubArray.getString(6); String sPlace = jsonSubArray.getString(7); String sDate = jsonSubArray.getString(8); String sMap = jsonSubArray.getString(9); if (!mmoItems.containsKey(nID)) { ScanexNotificationItem Item = new ScanexNotificationItem(c, nID, sPtCoord, nConfidence, nPower, sURL1, sURL2, sType, sPlace, sDate, sMap, R.drawable.ic_scan); mmoItems.put(Item.GetId(), Item); //notify changes c.onNewNotifictation(GetId(), Item); setHasNews(true); } } } else { SendError(object.getString("ErrorInfo")); } } catch (JSONException e) { SendError(e.getLocalizedMessage()); } /*44({ "Status": "OK", "ErrorInfo": "", "Result": [[1306601, "61.917, 63.090", 68, 27.4, "\u003ca href=\u0027http://maps.kosmosnimki.ru/TileService.ashx/apikeyV6IAK16QRG/mapT42E9?SERVICE=WMS&request=GetMap&version=1.3&layers=C7B2E6510209444E80673F3C37519F7E,FFE60CFA7DAF498381F811C08A5E8CF5,T42E9.A78AC25E0D924258B5AF40048C21F7E7_dt04102013&styles=&crs=EPSG:3395&transparent=FALSE&format=image/jpeg&width=460&height=460&bbox=6987987,8766592,7058307,8836912\u0027\u003e \u003cimg src=\u0027http://maps.kosmosnimki.ru/TileService.ashx/apikeyV6IAK16QRG/mapT42E9?SERVICE=WMS&request=GetMap&version=1.3&layers=C7B2E6510209444E80673F3C37519F7E,FFE60CFA7DAF498381F811C08A5E8CF5,T42E9.A78AC25E0D924258B5AF40048C21F7E7_dt04102013&styles=&crs=EPSG:3395&transparent=FALSE&format=image/jpeg&width=100&height=100&bbox=6987987,8766592,7058307,8836912\u0027 width=\u0027{4}\u0027 height=\u0027{5}\u0027 /\u003e\u003c/a\u003e", "\u003ca href=\u0027http://fires.kosmosnimki.ru/?x=63.09&y=61.917&z=11&dt=04.10.2013\u0027 target=\"_blank\"\u003eView on the map\u003c/a\u003e", "Fire", "", "\/Date(1380859500000)\/", "http://maps.kosmosnimki.ru/TileService.ashx/apikeyV6IAK16QRG/mapT42E9?SERVICE=WMS&request=GetMap&version=1.3&layers=C7B2E6510209444E80673F3C37519F7E,FFE60CFA7DAF498381F811C08A5E8CF5,T42E9.A78AC25E0D924258B5AF40048C21F7E7_dt04102013&styles=&crs=EPSG:3395&transparent=FALSE&format=image/jpeg&width=460&height=460&bbox=6987987,8766592,7058307,8836912", null]] })*/ }
From source file:com.hichinaschool.flashcards.libanki.sync.Syncer.java
private void mergeTags(JSONArray tags) { ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < tags.length(); i++) { try {/* w ww . ja v a 2 s.co m*/ list.add(tags.getString(i)); } catch (JSONException e) { throw new RuntimeException(e); } } mCol.getTags().register(list, mMaxUsn); }
From source file:com.dtz.plugins.azurehubnotification.AzureHubNotification.java
@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { Log.i(TAG, "Inside the Android Execute method..."); try {//from ww w . j a v a 2s . c o m if (ACTION_AZURE_HUB_NOTIFICATION_REGISTER.equalsIgnoreCase(action)) { Log.i(TAG, "Action : ACTION_AZURE_HUB_NOTIFICATION_REGISTER , Data : " + data); String handleTag = data.getString(0); registerForAzureNotificationHub(handleTag, callbackContext); return true; } else if (ACTION_AZURE_HUB_NOTIFICATION_UN_REGISTER.equalsIgnoreCase(action)) { Log.i(TAG, "Action : ACTION_AZURE_HUB_NOTIFICATION_UN_REGISTER"); unRegisterFromAzureNotificationHub(callbackContext); return true; } callbackContext.error("Invalid action"); return false; } catch (Exception ex) { Log.e(TAG, "Exception: " + ex.getMessage()); return false; } }
From source file:ca.canucksoftware.ipkpackager.IpkPackagerView.java
public void readFromControlFile(File control) { try {/*from ww w .j av a2 s . c om*/ BufferedReader input = new BufferedReader(new FileReader(control)); String line = input.readLine(); while (line != null) { line = line.trim(); if (line.length() > 0 && line.indexOf(":") != line.length() - 1) { if (line.startsWith("Package")) { jTextField5.setText(line.substring(line.indexOf(":") + 2)); } else if (line.startsWith("Description")) { jTextField3.setText(line.substring(line.indexOf(":") + 2)); } else if (line.startsWith("Version")) { jTextField6.setText( line.substring(line.indexOf(":") + 2).replaceAll("-", ".").replaceAll("_", ".")); } else if (line.startsWith("Architecture")) { setArch(line.substring(line.indexOf(":") + 2)); } else if (line.startsWith("Maintainer")) { jTextField7.setText(line.substring(line.indexOf(":") + 2)); } else if (line.startsWith("Depends")) { String[] tokens = line.substring(line.indexOf(":") + 2).split(","); for (int i = 0; i < tokens.length; i++) { tokens[i] = tokens[i].trim(); if (!depends.contains(tokens[i])) { depends.add(tokens[i]); } } jList2.setListData(depends.toArray()); } else if (line.startsWith("Source")) { JSONObject src = new JSONObject(line.substring(line.indexOf(":") + 2)); if (src.has("Icon")) { jTextField4.setText(src.getString("Icon")); } if (src.has("Screenshots")) { JSONArray ss = src.getJSONArray("Screenshots"); for (int i = 0; i < ss.length(); i++) { if (!ssURLs.contains(ss.getString(i))) { ssURLs.add(ss.getString(i)); } } jList1.setListData(ssURLs.toArray()); } if (src.has("FullDescription")) { jTextArea2.setText(src.getString("FullDescription").replaceAll("<br>", "\n")); } if (src.has("Homepage")) { jTextField9.setText(src.getString("Homepage")); } if (src.has("Type")) { setType(src.getString("Type")); } if (src.has("Category")) { jTextField12.setText(src.getString("Category")); } if (src.has("License")) { jTextField11.setText(src.getString("License")); } if (src.has("Location")) { jTextField10.setText(src.getString("Location")); } if (src.has("PostInstallFlags")) { setFlag(jComboBox2, src.getString("PostInstallFlags")); } if (src.has("PostUpdateFlags")) { setFlag(jComboBox3, src.getString("PostUpdateFlags")); } if (src.has("PostRemoveFlags")) { setFlag(jComboBox4, src.getString("PostRemoveFlags")); } } } line = input.readLine(); } } catch (Exception e) { } }
From source file:com.domuslink.api.DomusHandler.java
public String[] getFloorPlan() throws Exception { JSONArray theList = null; JSONObject theResponse = null;/*from w ww. java 2 s . c o m*/ String[] theFloorPlan; if (this.hostPath != null || this.hostPath.length() != 0) { ApiHandler.prepareUserAgent(this.c, authPass, hostPath); try { if (this.visible) theResponse = ApiHandler.getPageContent(this, "floorplan", "true"); else theResponse = ApiHandler.getPageContent(this, "floorplan", "false"); } catch (Exception e) { Log.e(TAG, "Error getting floorplan page content at " + this.hostPath, e); throw e; } try { theList = theResponse.getJSONArray("floorplan"); } catch (Exception e) { Log.e(TAG, "Error getting floorplan from JSONObject", e); throw e; } theFloorPlan = new String[theList.length()]; for (int i = 0; i < theList.length(); i++) { try { theFloorPlan[i] = theList.getString(i); } catch (Exception e) { Log.e(TAG, "Error getting floorplan from JSONArray", e); throw e; } } } else theFloorPlan = EMPTY_LIST; return theFloorPlan; }
From source file:fi.harism.lucidchat.api.ChatConnection.java
/** * Handle server event messages./*from ww w . ja va 2 s . c o m*/ */ private void handleEvent(String message) { try { // We receive always JSON messages. JSONObject json = new JSONObject(message); // Get event type from JSON. String event = json.optString("event"); // Handle session_created event. if (event.equals("session_created")) { // Here we expect that server sends user_auth only when new // session is created. In case where old session was continues // user_auth ought not to be present. if (!json.has("user_auth")) { // Notify server about connection. mObserver.onServerMessage(new Message(Message.TYPE_LOG, "Session resumed userId=" + mUserId + " sessionId=" + mSessionId)); mObserver.onConnect(mUserId, mUserAuth, mSessionId); } else { // New session was created. mUserId = json.getString("user_id"); mUserAuth = json.getString("user_auth"); mSessionId = json.getString("session_id"); mObserver.onServerMessage(new Message(Message.TYPE_LOG, "Session created userId=" + mUserId + " sessionId=" + mSessionId)); mObserver.onConnect(mUserId, mUserAuth, mSessionId); // If autojoin is enabled send join message. if (mAutojoin) { sendJoinChannel(NINCHAT_LOUNGE); } } } // Handle user_updated and user_found events. if (event.equals("user_updated") || event.equals("user_found")) { String userId = json.getString("user_id"); // If update was sent for ourself. if (userId.equals(mUserId)) { // We do nothing on updates sent to self at the moment. } else { // Notify observer about user updated event. JSONObject userAttrs = json.getJSONObject("user_attrs"); String name = userAttrs.optString("name"); String realName = userAttrs.optString("realname"); boolean connected = userAttrs.optBoolean("connected"); mObserver.onUserUpdated(new User(userId, name, realName, connected)); } } // Handle channel_updated event. if (event.equals("channel_updated")) { String channelId = json.getString("channel_id"); JSONObject channelAttrs = json.getJSONObject("channel_attrs"); String name = channelAttrs.optString("name"); String topic = channelAttrs.optString("topic"); mObserver.onChannelUpdated(new Channel(channelId, name, topic)); } // Handle search_results event. if (event.equals("search_results")) { mObserver.onServerMessage(new Message(Message.TYPE_LOG, "Search results event")); Vector<Channel> channelList = new Vector<Channel>(); // Parse channels from search results. JSONObject channels = json.optJSONObject("channels"); if (channels != null) { JSONArray names = channels.names(); for (int i = 0; i < names.length(); ++i) { String channelId = names.getString(i); JSONObject channelAttrs = channels.getJSONObject(channelId).getJSONObject("channel_attrs"); String name = channelAttrs.optString("name"); String topic = channelAttrs.optString("topic"); channelList.add(new Channel(channelId, name, topic)); } } // Parse users from search results. Vector<User> userList = new Vector<User>(); JSONObject users = json.optJSONObject("users"); if (users != null) { JSONArray names = users.names(); for (int i = 0; i < names.length(); ++i) { String userId = names.getString(i); if (!userId.equals(mUserId)) { JSONObject user = users.getJSONObject(userId); String name = user.optString("name"); String realName = user.optString("realname"); boolean connected = user.optBoolean("connected"); userList.add(new User(userId, name, realName, connected)); } } } mObserver.onSearchResults(channelList, userList); } // Handle channel_joined event. if (event.equals("channel_joined")) { mObserver.onServerMessage(new Message(Message.TYPE_LOG, "Channel joined event")); String channelId = json.getString("channel_id"); Vector<User> userList = new Vector<User>(); JSONObject channelMembers = json.getJSONObject("channel_members"); JSONArray names = channelMembers.names(); for (int i = 0; i < names.length(); ++i) { String userId = names.getString(i); JSONObject userAttrs = channelMembers.getJSONObject(userId).getJSONObject("user_attrs"); if (!userId.equals(mUserId)) { String name = userAttrs.optString("name"); String realName = userAttrs.optString("realname"); boolean connected = userAttrs.optBoolean("connected"); userList.add(new User(userId, name, realName, connected)); } } JSONObject channelAttrs = json.getJSONObject("channel_attrs"); String name = channelAttrs.getString("name"); String topic = channelAttrs.getString("topic"); mObserver.onChannelJoined(new Channel(channelId, name, topic), userList); } // Message receiving happens with 2 callbacks. First // message_received is sent from server and then an empty JSON with // message only. if (event.equals("message_received")) { // Check message_type. We handle only text messages. if (json.optString("message_type").equals("ninchat.com/text")) { mMessage = json; } if (json.optString("message_type").equals("ninchat.com/info")) { mMessage = json; } } // Second part of text message receiving. if (mMessage != null && mMessage.optString("message_type").equals("ninchat.com/text") && json.has("text")) { // Message time is in seconds after epoch. long messageTime = mMessage.getLong("message_time") * 1000; String messageUserName = mMessage.getString("message_user_name"); String channelId = mMessage.optString("channel_id"); String userId = mMessage.optString("user_id"); String text = json.getString("text"); mMessage = null; // If channel_id exists notify observer about channel message. if (channelId.length() > 0) { mObserver.onChannelMessage(channelId, new Message(Message.TYPE_CONVERSATION, messageTime, messageUserName, text)); } // If user_id exists notify observer about private message. if (userId.length() > 0) { User user = new User(userId, messageUserName, "", true); mObserver.onUserMessage(user, new Message(Message.TYPE_CONVERSATION, messageTime, messageUserName, text)); } } if (mMessage != null && mMessage.optString("message_type").equals("ninchat.com/info") && json.has("info")) { String info = json.getString("info"); if (info.equals("join")) { String channelId = mMessage.getString("channel_id"); String userId = json.getString("user_id"); String userName = json.getString("user_name"); mObserver.onInfoJoin(channelId, userId, userName); } if (info.equals("part")) { String channelId = mMessage.getString("channel_id"); String userId = json.getString("user_id"); String userName = json.getString("user_name"); mObserver.onInfoPart(channelId, userId, userName); } mMessage = null; } // Handle channel_parted event. if (event.equals("channel_parted")) { String channelId = json.getString("channel_id"); mObserver.onChannelParted(channelId); } // Handle channel_member_joined. if (event.equals("channel_member_joined")) { String channelId = json.getString("channel_id"); String userId = json.getString("user_id"); JSONObject userAttrs = json.getJSONObject("user_attrs"); String name = userAttrs.getString("name"); String realname = userAttrs.optString("realname"); boolean connected = userAttrs.optBoolean("connected"); mObserver.onUserJoin(channelId, new User(userId, name, realname, connected)); } // Handle channel_member_parted. if (event.equals("channel_member_parted")) { String channelId = json.getString("channel_id"); String userId = json.getString("user_id"); mObserver.onUserPart(channelId, userId); } // Handle second phase of delete_user. if (event.equals("user_deleted")) { mWSC.disconnect(); } } catch (JSONException ex) { ex.printStackTrace(); } }
From source file:com.phonegap.plugins.xapkreader.XAPKReader.java
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("get")) { final String filename = args.getString(0); try {/* w w w .j av a2s .c om*/ Context ctx = cordova.getActivity().getApplicationContext(); // Read file as array buffer byte[] data = XAPKReader.readFile(ctx, filename); if (null != data) { // Encode to Base64 string String encoded = Base64.encodeToString(data, Base64.DEFAULT); // Return file data as base64 string callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, encoded)); } else { callbackContext.error("File not found."); } } catch (Exception e) { e.printStackTrace(); callbackContext.error(e.getMessage()); } return true; } return false; }
From source file:com.polyvi.xface.extension.advancedfiletransfer.XAdvancedFileTransferExt.java
@Override public XExtensionResult exec(String action, JSONArray args, XCallbackContext callbackCtx) throws JSONException { String source = null;//www . j a va 2s.c o m String target = null; String appId = mWebContext.getApplication().getAppId(); try { if (action.equals(COMMAND_DOWNLOAD)) { source = args.getString(0); target = args.getString(1); download(mWebContext, source, target, callbackCtx); XLog.d(CLASS_NAME, "*** About to return a result from download"); return new XExtensionResult(XExtensionResult.Status.NO_RESULT); } else if (action.equals(COMMAND_UPLOAD)) { source = args.getString(0); target = args.getString(1); upload(mWebContext, source, target, callbackCtx); XLog.d(CLASS_NAME, "*** About to return a result from upload"); return new XExtensionResult(XExtensionResult.Status.NO_RESULT); } else if (action.equals(COMMAND_PAUSE)) { source = args.getString(0); mFileTransferManager.pause(appId, source); return new XExtensionResult(XExtensionResult.Status.OK); } else if (action.equals(COMMAND_CANCEL)) { source = args.getString(0); target = args.getString(1); boolean isUpload = args.getBoolean(2); if (isUpload) { mFileTransferManager.cancel(appId, source, null, COMMAND_UPLOAD); } else { target = new File(mWebContext.getWorkSpace(), target).getAbsolutePath(); mFileTransferManager.cancel(mWebContext.getApplication().getAppId(), source, target, COMMAND_DOWNLOAD); } return new XExtensionResult(XExtensionResult.Status.OK); } } catch (FileNotFoundException e) { XLog.e(CLASS_NAME, e.getMessage()); JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target); return new XExtensionResult(XExtensionResult.Status.ERROR, error); } catch (IllegalArgumentException e) { XLog.e(CLASS_NAME, e.getMessage()); JSONObject error = createFileTransferError(INVALID_URL_ERR, source, target); return new XExtensionResult(XExtensionResult.Status.ERROR, error); } catch (IOException e) { XLog.e(CLASS_NAME, e.getMessage()); JSONObject error = createFileTransferError(CONNECTION_ERR, source, target); return new XExtensionResult(XExtensionResult.Status.ERROR, error); } catch (JSONException e) { XLog.e(CLASS_NAME, e.getMessage(), e); return new XExtensionResult(XExtensionResult.Status.JSON_EXCEPTION); } return new XExtensionResult(XExtensionResult.Status.INVALID_ACTION); }
From source file:com.imaginary.home.cloud.device.Light.java
static void mapLight(@Nonnull ControllerRelay relay, @Nonnull JSONObject json, @Nonnull Map<String, Object> state) throws JSONException { mapPoweredDevice(relay, json, state); state.put("deviceType", "light"); if (json.has("color")) { JSONObject color = json.getJSONObject("color"); ColorMode colorMode = null;//from w ww. java2 s . c o m float[] components = null; if (color.has("colorMode") && !color.isNull("colorMode")) { try { colorMode = ColorMode.valueOf(color.getString("colorMode")); } catch (IllegalArgumentException e) { throw new JSONException("Invalid color mode: " + color.getString("colorMode")); } } if (color.has("components") && !color.isNull("components")) { JSONArray arr = color.getJSONArray("components"); components = new float[arr.length()]; for (int i = 0; i < arr.length(); i++) { components[i] = (float) arr.getDouble(i); } } if (colorMode != null || components != null) { state.put("colorMode", colorMode); state.put("colorValues", components); } } if (json.has("brightness") && !json.isNull("brightness")) { state.put("brightness", (float) json.getDouble("brightness")); } if (json.has("supportsColorChanges")) { state.put("colorChangeSupported", !json.isNull("supportsColorChanges") && json.getBoolean("supportsColorChanges")); } if (json.has("supportsBrightnessChanges")) { state.put("dimmable", !json.isNull("supportsBrightnessChanges") && json.getBoolean("supportsBrightnessChanges")); } if (json.has("colorModes")) { JSONArray arr = json.getJSONArray("colorModes"); ColorMode[] modes = new ColorMode[arr.length()]; for (int i = 0; i < arr.length(); i++) { try { modes[i] = ColorMode.valueOf(arr.getString(i)); } catch (IllegalArgumentException e) { throw new JSONException("Invalid color mode: " + arr.getString(i)); } } state.put("colorModesSupported", modes); } }
From source file:io.selendroid.server.RequestHandler.java
protected String[] extractKeysToSendFromPayload(HttpRequest request) throws JSONException { JSONArray valueArr = getPayload(request).getJSONArray("value"); if (valueArr == null || valueArr.length() == 0) { throw new SelendroidException("No key to send to an element was found."); }// w w w . j av a2 s . c om String[] toReturn = new String[valueArr.length()]; for (int i = 0; i < valueArr.length(); i++) { toReturn[i] = valueArr.getString(i); } return toReturn; }