List of usage examples for org.json JSONArray get
public Object get(int index) throws JSONException
From source file:com.eventattend.portal.bl.FaceBookBL.java
public FaceBookDTO checkAlreadyFriend(FaceBookDTO faceBookDTO) { FacebookJsonRestClient userClient = null; JSONArray jsonArray = null; userClient = getUserClient((String) faceBookDTO.getAccessToken()); String friendId = faceBookDTO.getProfileId(); System.out.println("Facebook friendId>>> " + friendId); // faceBookDTO = new FaceBookDTO(); faceBookDTO.setProfileId(friendId);// w w w . j av a 2s .c o m try { jsonArray = userClient.friends_get(); } catch (FacebookException e1) { e1.printStackTrace(); } for (int i = 0; i < jsonArray.length(); i++) { try { Object uId = (Object) jsonArray.get(i); System.out.println("Facebook>>> " + uId); if ((uId.toString()).equals(friendId)) { System.out.println(friendId + " FB Already a Friend !"); faceBookDTO.setAlreadyFriends(true); } System.out.println(">> " + uId); } catch (JSONException e) { e.printStackTrace(); } } return faceBookDTO; }
From source file:com.eventattend.portal.bl.FaceBookBL.java
public FaceBookDTO inviteFriend(FaceBookDTO faceBookDTO) { FacebookJsonRestClient userClient = null; boolean inviteStatus = false; userClient = getUserClient((String) faceBookDTO.getAccessToken()); String friendId = faceBookDTO.getProfileId(); System.out.println("Facebook inviteFriend >>> " + friendId); try {//from w w w. j a va2s .com JSONObject jsonObject = userClient.notifications_get(); JSONArray jsonArray = jsonObject.getJSONArray("friend_requests"); for (int i = 0; i < jsonArray.length(); i++) { try { Object uId = (Object) jsonArray.get(i); if (uId.toString().equals(friendId)) { System.out.println("Has Already invite you & Accept request in FB >>> " + friendId); inviteStatus = true; } else { inviteStatus = false; } } catch (JSONException e) { e.printStackTrace(); } } } catch (JSONException e) { e.printStackTrace(); } catch (FacebookException e) { inviteStatus = false; e.printStackTrace(); } faceBookDTO.setFriendAlreadyReqYou(inviteStatus); return faceBookDTO; }
From source file:com.eventattend.portal.bl.FaceBookBL.java
private List personFBFriendsProfile(FacebookJsonRestClient userClient, long userId) { JSONArray jsonArray = null; List friendsList = null;//from w w w . jav a 2 s. co m List friendsIds = null; friendsIds = new ArrayList(); JSONObject jsonObject = null; try { jsonArray = userClient.friends_get(); for (int i = 0; i < jsonArray.length(); i++) { try { Object uId = (Object) jsonArray.get(i); userId = Long.parseLong(uId.toString()); friendsIds.add(userId); } catch (JSONException e) { e.printStackTrace(); } } jsonArray = userClient.users_getInfo(friendsIds, fields); friendsList = personFBFriendsList(jsonArray); } catch (FacebookException e) { e.printStackTrace(); } return friendsList; }
From source file:com.eventattend.portal.bl.FaceBookBL.java
/** * @param userClient//from w ww. jav a 2 s .co m * @return */ private List getFriendsProfile(FacebookJsonRestClient userClient) { JSONArray jsonArray = null; List friendsList = null; List friendsIds = null; FaceBookDTO faceBookDTO = null; friendsIds = new ArrayList(); JSONObject jsonObject = null; long userId = 0; try { userId = userClient.users_getLoggedInUser(); jsonArray = userClient.friends_get(userId); for (int i = 0; i < jsonArray.length(); i++) { try { Object uId = (Object) jsonArray.get(i); userId = Long.parseLong(uId.toString()); friendsIds.add(userId); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } jsonArray = userClient.users_getInfo(friendsIds, fields); friendsList = getFriendsList(jsonArray); } catch (FacebookException e) { e.printStackTrace(); } return friendsList; }
From source file:net.netheos.pcsapi.credentials.AppInfoFileRepository.java
public AppInfoFileRepository(File file) throws IOException { this.file = file; BufferedReader reader = null; try {// w w w . j a va 2 s . c om reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), PcsUtils.UTF8)); String line; while ((line = reader.readLine()) != null) { // while loop begins here line = line.trim(); if (line.startsWith("#") || line.length() == 0) { continue; } String[] appInfoArray = line.split("=", 2); // Key String[] appInfoKeyArray = appInfoArray[0].trim().split("\\."); String providerName = appInfoKeyArray[0]; String appName = appInfoKeyArray[1]; String appInfoValue = appInfoArray[1].trim(); JSONObject jsonObj = (JSONObject) new JSONTokener(appInfoValue).nextValue(); String appId = jsonObj.optString("appId", null); AppInfo appInfo; if (appId != null) { // OAuth JSONArray jsonScope = jsonObj.optJSONArray("scope"); List<String> scopeList = new ArrayList<String>(); for (int i = 0; i < jsonScope.length(); i++) { scopeList.add(jsonScope.get(i).toString()); } String appSecret = jsonObj.getString("appSecret"); String redirectUrl = jsonObj.optString("redirectUrl", null); appInfo = new OAuth2AppInfo(providerName, appName, appId, appSecret, scopeList, redirectUrl); } else { // Login / Password appInfo = new PasswordAppInfo(providerName, appName); } appInfoMap.put(getAppKey(providerName, appName), appInfo); } } finally { PcsUtils.closeQuietly(reader); } }
From source file:com.flym.echo24.activity.EditFeedActivity.java
/** * This is where the bulk of our work is done. This function is called in a background thread and should generate a new set of data to be * published by the loader.//from w ww .ja v a2s . c o m */ @Override public ArrayList<HashMap<String, String>> loadInBackground() { try { HttpURLConnection conn = NetworkUtils .setupConnection("https://ajax.googleapis.com/ajax/services/feed/find?v=1.0&q=" + mSearchText); try { String jsonStr = new String(NetworkUtils.getBytes(conn.getInputStream())); // Parse results final ArrayList<HashMap<String, String>> results = new ArrayList<>(); JSONObject response = new JSONObject(jsonStr).getJSONObject("responseData"); JSONArray entries = response.getJSONArray("entries"); for (int i = 0; i < entries.length(); i++) { try { JSONObject entry = (JSONObject) entries.get(i); String url = entry.get(EditFeedActivity.FEED_SEARCH_URL).toString(); if (!url.isEmpty()) { HashMap<String, String> map = new HashMap<>(); map.put(EditFeedActivity.FEED_SEARCH_TITLE, Html .fromHtml(entry.get(EditFeedActivity.FEED_SEARCH_TITLE).toString()).toString()); map.put(EditFeedActivity.FEED_SEARCH_URL, url); map.put(EditFeedActivity.FEED_SEARCH_DESC, Html .fromHtml(entry.get(EditFeedActivity.FEED_SEARCH_DESC).toString()).toString()); results.add(map); } } catch (Exception ignored) { } } return results; } finally { conn.disconnect(); } } catch (Exception e) { return null; } }
From source file:com.roiland.crm.sm.core.service.impl.ContacterAPIImpl.java
@Override public Contacter createContacter(String userID, String dealerOrgID, Contacter contacter) throws ResponseException { // ?//from www . ja va2s .c o m Contacter returnContacter = null; try { if (userID == null || dealerOrgID == null) { throw new ResponseException("userID or dealerOrgID is null."); } JSONObject params = new JSONObject(); params.put("userID", userID); params.put("dealerOrgID", dealerOrgID); params.put("projectID", contacter.getProjectID()); params.put("customerID", contacter.getCustomerID()); params.put("contName", contacter.getContName()); params.put("contMobile", contacter.getContMobile()); params.put("contOtherPhone", contacter.getContOtherPhone()); params.put("isPrimContanter", contacter.getIsPrimContanter()); params.put("contGenderCode", contacter.getContGenderCode()); params.put("contBirthday", contacter.getContBirthday()); params.put("idNumber", contacter.getIdNumber()); params.put("ageScopeCode", contacter.getAgeScopeCode()); params.put("contTypeCode", contacter.getContTypeCode()); params.put("contRelationCode", contacter.getContRelationCode()); if (contacter.getLicenseValid() == 0) { params.put("licenseValid", null); } else params.put("licenseValid", contacter.getLicenseValid()); RLHttpResponse response = getHttpClient() .executePostJSON(getURLAddress(URLContact.METHOD_CREATE_CONTACTER), params, null); if (response.isSuccess()) { returnContacter = contacter; JSONObject result = new JSONObject(getSimpleString(response)); String node = null; String error = null; JSONArray nodeArray = result.names(); if (nodeArray != null) { for (int i = 0; i < nodeArray.length(); i++) { node = nodeArray.get(i).toString(); if (node.equalsIgnoreCase("success")) { Boolean success = Boolean.parseBoolean(result.getString("success")); if (success) { // ?ID returnContacter.setContacterID(result.getString("contacterID")); } } else if (node.equalsIgnoreCase("validate_error")) { error = parsingValidation(result.getJSONObject(node)); throw new ResponseException(error); } } } return returnContacter; } throw new ResponseException(); } catch (IOException e) { Log.e(tag, "Connection network error.", e); throw new ResponseException(e); } catch (JSONException e) { Log.e(tag, "Parsing data error.", e); throw new ResponseException(e); } }
From source file:com.roiland.crm.sm.core.service.impl.ContacterAPIImpl.java
@Override public Contacter updateContacter(String userID, String dealerOrgID, Contacter contacter) throws ResponseException { // ?/* w w w . ja v a 2s . c o m*/ Contacter returnContacter = null; try { if (userID == null || dealerOrgID == null) { throw new ResponseException("userID or dealerOrgID is null."); } JSONObject params = new JSONObject(); params.put("userID", userID); params.put("dealerOrgID", dealerOrgID); params.put("projectID", contacter.getProjectID()); params.put("customerID", contacter.getCustomerID()); params.put("contacterID", contacter.getContacterID()); params.put("contName", contacter.getContName()); params.put("contMobile", contacter.getContMobile()); params.put("contOtherPhone", contacter.getContOtherPhone()); params.put("isPrimContanter", Boolean.parseBoolean(contacter.getIsPrimContanter())); params.put("contGenderCode", contacter.getContGenderCode()); params.put("contBirthday", contacter.getContBirthday()); params.put("idNumber", contacter.getIdNumber()); params.put("ageScopeCode", contacter.getAgeScopeCode()); params.put("contTypeCode", contacter.getContTypeCode()); params.put("contRelationCode", contacter.getContRelationCode()); if (contacter.getLicenseValid() == 0) params.put("licenseValid", null); else params.put("licenseValid", contacter.getLicenseValid()); RLHttpResponse response = getHttpClient() .executePostJSON(getURLAddress(URLContact.METHOD_UPDATE_CONTACTER), params, null); if (response.isSuccess()) { returnContacter = contacter; JSONObject result = new JSONObject(getSimpleString(response)); // ?? String node = null; String error = null; JSONArray nodeArray = result.names(); if (nodeArray != null) { for (int i = 0; i < nodeArray.length(); i++) { node = nodeArray.get(i).toString(); if (node.equalsIgnoreCase("success")) { Boolean success = Boolean.parseBoolean(result.getString("success")); // if (success) { // // ?ID // returnContacter.setContacterID(result.getString("contacterID")); // } } else if (node.equalsIgnoreCase("validate_error")) { error = parsingValidation(result.getJSONObject(node)); throw new ResponseException(error); } } } return returnContacter; } throw new ResponseException(); } catch (IOException e) { Log.e(tag, "Connection network error.", e); throw new ResponseException(e); } catch (JSONException e) { Log.e(tag, "Parsing data error.", e); throw new ResponseException(e.getMessage()); } }
From source file:org.wso2.carbon.ml.integration.common.utils.MLHttpClient.java
/** * Get a ID of the first version-set of a dataset * //from w w w . j a v a 2 s . c o m * @param datasetId ID of the dataset * @return ID of the first versionset of the dataset * @throws ClientProtocolException * @throws MLHttpClientException */ public int getAVersionSetIdOfDataset(int datasetId) throws MLHttpClientException { CloseableHttpResponse response; try { response = doHttpGet("/api/datasets/" + datasetId + "/versions"); // Get the Id of the first dataset BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); JSONArray responseJson = new JSONArray(bufferedReader.readLine()); JSONObject datsetVersionJson = (JSONObject) responseJson.get(0); return datsetVersionJson.getInt("id"); } catch (Exception e) { throw new MLHttpClientException("Failed to get a version set ID of dataset: " + datasetId, e); } }
From source file:com.chainsaw.clearweather.BackgroundFetch.java
@Override protected WeatherData doInBackground(String... params) { publishProgress(10);//from w w w . jav a 2s .c om HttpURLConnection con = null; InputStream is = null; if (!isNetworkAvailable()) { fetchStatus = NO_NETWORK; } if (isNetworkAvailable()) { try { con = (HttpURLConnection) (new URL(params[0])).openConnection(); con.setRequestMethod("GET"); con.setDoInput(true); con.setDoOutput(true); con.setConnectTimeout(SERVER_TIMEOUT); con.connect(); buffer = new StringBuffer(); is = con.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = null; while ((line = br.readLine()) != null) buffer.append(line); is.close(); con.disconnect(); } catch (Throwable t) { fetchStatus = SERVER_ERROR; t.printStackTrace(); } finally { try { is.close(); } catch (Throwable t) { fetchStatus = SERVER_ERROR; t.printStackTrace(); } try { con.disconnect(); } catch (Throwable t) { fetchStatus = SERVER_ERROR; t.printStackTrace(); } } try { weatherData = (buffer.toString() == null) ? new JSONObject() : new JSONObject(buffer.toString()); fetchStatus = DONE; } catch (Throwable e) { fetchStatus = NO_DATA; e.printStackTrace(); } is = null; con = null; try { if ((fetchStatus == DONE) && (weatherData != null)) { WeatherData.newDataStatus = DONE; JSONObject mainObj = weatherData.getJSONObject("main"); JSONArray weatherObj = weatherData.getJSONArray("weather"); returnData = new WeatherData(true, (int) (Math.round(mainObj.getDouble("temp") - 273.15)), ((int) (Math.round(mainObj.getInt("humidity")))), weatherData.getString("name"), ((JSONObject) weatherObj.get(0)).getString("description")); } } catch (Throwable e) { fetchStatus = NO_DATA; e.printStackTrace(); } } switch (fetchStatus) { case NO_DATA: WeatherData.newDataStatus = NO_DATA; break; case SERVER_ERROR: WeatherData.newDataStatus = SERVER_ERROR; break; case NO_NETWORK: WeatherData.newDataStatus = NO_NETWORK; break; } if (returnData == null) WeatherData.newDataStatus = NO_DATA; return returnData; }