List of usage examples for org.json JSONObject get
public Object get(String key) throws JSONException
From source file:com.leanengine.JsonDecode.java
static Map<String, Object> entityPropertiesFromJson(JSONObject jsonNode) throws LeanException, JSONException { Map<String, Object> props = new HashMap<String, Object>(jsonNode.length()); // must have some properties if (jsonNode.length() == 0) throw new LeanException(LeanError.Type.ServerError, "Empty reply."); Iterator fieldNames = jsonNode.keys(); while (fieldNames.hasNext()) { String field = (String) fieldNames.next(); // skip LeanEngine system properties (starting with underscore '_') if (field.startsWith("_")) continue; Object subNode = jsonNode.get(field); props.put(field, propertyFromJson(subNode)); }// ww w .j a v a2 s .c o m return props; }
From source file:com.microsoft.services.sharepoint.OfficeEntity.java
/** * Gets the data./*from www. java 2 s.c o m*/ * * @param field * the field * @return the data */ public Object getData(String field) { try { JSONObject innerJson; if (mJsonData.has("d")) { innerJson = mJsonData.getJSONObject("d"); return innerJson.get(field); } else { return mJsonData.get(field); } } catch (JSONException e) { throw new IllegalArgumentException("Invalid field name " + field, e); } }
From source file:com.pimp.companionforband.fragments.cloud.SummariesFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); summariesLV = (ListView) view.findViewById(R.id.summaries_listview); statusTV = (TextView) view.findViewById(R.id.status_textview); stringArrayList = new ArrayList<>(); stringArrayAdapter = new ArrayAdapter<>(getContext(), R.layout.activities_list_item, R.id.list_item_textView, stringArrayList); summariesLV.setAdapter(stringArrayAdapter); RequestQueue queue = Volley.newRequestQueue(getContext()); JsonObjectRequest profileRequest = new JsonObjectRequest(Request.Method.GET, CloudConstants.BASE_URL + CloudConstants.Summaries_URL + "Daily?startTime=2015-01-01T16%3A04%3A49.8578590-07%3A00", null, new Response.Listener<JSONObject>() { @Override/*w w w. j ava 2 s . c om*/ public void onResponse(JSONObject response) { statusTV.setText("CSV file can be found in CompanionForBand/Summaries\n"); Iterator<String> stringIterator = response.keys(); while (stringIterator.hasNext()) { try { String key = stringIterator.next(); JSONArray jsonArray = response.getJSONArray(key); String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "CompanionForBand" + File.separator + "Summaries"; File file = new File(path); file.mkdirs(); JsonFlattener parser = new JsonFlattener(); CSVWriter writer = new CSVWriter(); try { List<LinkedHashMap<String, String>> flatJson = parser .parseJson(jsonArray.toString()); writer.writeAsCSV(flatJson, path + File.separator + key + ".csv"); } catch (Exception e) { Log.e("SummariesParseJson", e.toString()); } for (int i = 0; i < jsonArray.length(); i++) { JSONObject activity = jsonArray.getJSONObject(i); Iterator<String> iterator = activity.keys(); String str = ""; while (iterator.hasNext()) { key = iterator.next(); str = str + UIUtils.splitCamelCase(key) + " : " + activity.get(key).toString() + "\n"; } stringArrayAdapter.add(str); } } catch (Exception e) { Log.e("Summaries", e.toString()); } } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_LONG).show(); } }) { @Override public Map<String, String> getHeaders() throws AuthFailureError { HashMap<String, String> headers = new HashMap<>(); headers.put("Authorization", "Bearer " + MainActivity.sharedPreferences.getString("access_token", "hi")); return headers; } }; queue.add(profileRequest); }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private String noteCall(String message, String subject, String friendID) throws EasyFacebookError { String postID = null;// ww w . j ava2s . c o m Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("message", message); params.putString("subject", subject); if (friendID == null) friendID = "me"; try { String jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/notes", "POST", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } JSONObject json = new JSONObject(jsonResponse); if (json.has("id")) postID = json.get("id").toString(); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return postID; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
public String commetReply(String message, String commentID) throws EasyFacebookError { String postID = null;/*from w ww. j ava 2 s . c o m*/ Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("message", message); try { String jsonResponse = Util.openUrl("https://graph.facebook.com/" + commentID + "/comments", "POST", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } JSONObject json = new JSONObject(jsonResponse); if (json.has("id")) postID = json.get("id").toString(); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return postID; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private String postLocation(String message, String friendID, String longitude, String latitude, String pagePlaceID, ArrayList<String> userIdTag) throws EasyFacebookError { String postID = null;// w w w . ja va2s .co m Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("message", message); params.putString("coordinates", "{\"latitude\": \"" + latitude + "\", \"longitude\": \"" + longitude + "\"}"); params.putString("place", pagePlaceID); String tag = ""; int flagtag = 0; for (String idtag : userIdTag) { tag = tag + "," + idtag; flagtag = 1; } if (flagtag == 1) { tag = tag.substring(1, tag.length()); } params.putString("tags", tag); if (friendID == null) friendID = "me"; try { String jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/checkins", "POST", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } JSONObject json = new JSONObject(jsonResponse); if (json.has("id")) postID = json.get("id").toString(); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return postID; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private String postCall(String message, String friendID, String urlPicture, String actionsUrl, String actionsName, String link, String name, String privacy, String countries, String regions, String locales, String description) throws EasyFacebookError { String postID = null;/*from w ww.j a v a 2 s. com*/ Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("message", message); if (description != null) params.putString("description", description); if (actionsUrl != null && actionsName != null) params.putString("actions", "{\"name\": \"" + actionsName + "\", \"link\": \"" + actionsUrl + "\"}"); if (name != null) params.putString("name", name); if (link != null) params.putString("link", link); if (privacy != null) params.putString("privacy", privacy); if (countries != null && regions != null && locales != null) params.putString("targeting", "{\"countries\": \"" + countries + "\", \"regions\": \"" + regions + "\", \"locales\": \"" + locales + "\"}"); if (urlPicture != null) params.putString("picture", urlPicture); if (friendID == null) friendID = "me"; try { String jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/feed", "POST", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } JSONObject json = new JSONObject(jsonResponse); if (json.has("id")) postID = json.get("id").toString(); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return postID; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private String uploadPhotoCall(String message, String friendIDorAlbumID, String urlPicture) throws EasyFacebookError { String postID = null;// w w w . j a v a 2 s. c om Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("message", message); if (urlPicture != null) { String pictureName = urlPicture.substring(urlPicture.lastIndexOf('/'), urlPicture.length()); params.putByteArray(pictureName, Util.loadPicture(urlPicture)); } if (friendIDorAlbumID == null) friendIDorAlbumID = "me"; try { String jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendIDorAlbumID + "/photos", "POST", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } JSONObject json = new JSONObject(jsonResponse); if (json.has("id")) postID = json.get("id").toString(); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return postID; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private String createEventsCall(long startTime, long endTime, String name, String urlPicture, String privacy, String description, String location, String street, String city, String state, String country, String latitude, String longitude, String zip) throws EasyFacebookError { String eventID = null;/*www .j a v a 2 s. co m*/ Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("start_time", Long.toString(startTime).substring(0, 10)); params.putString("end_time", Long.toString(endTime).substring(0, 10)); params.putString("name", name); params.putString("description", description); params.putString("location", location); params.putString("street", street); params.putString("city", city); params.putString("state", state); params.putString("country", country); params.putString("latitude", latitude); params.putString("longitude", longitude); params.putString("zip", zip); params.putString("privacy", privacy); if (urlPicture != null) { String pictureName = urlPicture.substring(urlPicture.lastIndexOf('/'), urlPicture.length()); params.putByteArray(pictureName, Util.loadPicture(urlPicture)); } try { String jsonResponse = Util.openUrl("https://graph.facebook.com/me/events", "POST", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } JSONObject json = new JSONObject(jsonResponse); if (json.has("id")) eventID = json.get("id").toString(); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return eventID; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private String createAlbumCall(String albumName, String description, String location) throws EasyFacebookError { String albumID = ""; Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("name", albumName); params.putString("message", description); params.putString("location", location); String jsonResponse;// w ww . j a v a2 s. com try { jsonResponse = Util.openUrl("https://graph.facebook.com/me/albums", "POST", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } JSONObject json = new JSONObject(jsonResponse); if (json.has("id")) albumID = json.get("id").toString(); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return albumID; }