List of usage examples for org.json JSONObject put
public JSONObject put(String key, Object value) throws JSONException
From source file:com.comcast.oscar.ber.OIDToJSONArray.java
/** * // w w w. jav a 2 s .co m * @param joSnmpDictionary * @return JSONObject * @throws JSONException */ public JSONObject updateSnmpJsonObject(JSONObject joSnmpDictionary) throws JSONException { return joSnmpDictionary.put(Dictionary.VALUE, toJSONArray()); }
From source file:com.trk.aboutme.facebook.TestSession.java
private static synchronized void retrieveTestAccountsForAppIfNeeded() { if (appTestAccounts != null) { return;/*from w w w . j a v a2s.c om*/ } appTestAccounts = new HashMap<String, TestAccount>(); // The data we need is split across two different FQL tables. We construct two queries, submit them // together (the second one refers to the first one), then cross-reference the results. // Get the test accounts for this app. String testAccountQuery = String.format("SELECT id,access_token FROM test_account WHERE app_id = %s", testApplicationId); // Get the user names for those accounts. String userQuery = "SELECT uid,name FROM user WHERE uid IN (SELECT id FROM #test_accounts)"; Bundle parameters = new Bundle(); // Build a JSON string that contains our queries and pass it as the 'q' parameter of the query. JSONObject multiquery; try { multiquery = new JSONObject(); multiquery.put("test_accounts", testAccountQuery); multiquery.put("users", userQuery); } catch (JSONException exception) { throw new FacebookException(exception); } parameters.putString("q", multiquery.toString()); // We need to authenticate as this app. parameters.putString("access_token", getAppAccessToken()); Request request = new Request(null, "fql", parameters, null); Response response = request.executeAndWait(); if (response.getError() != null) { throw response.getError().getException(); } FqlResponse fqlResponse = response.getGraphObjectAs(FqlResponse.class); GraphObjectList<FqlResult> fqlResults = fqlResponse.getData(); if (fqlResults == null || fqlResults.size() != 2) { throw new FacebookException("Unexpected number of results from FQL query"); } // We get back two sets of results. The first is from the test_accounts query, the second from the users query. Collection<TestAccount> testAccounts = fqlResults.get(0).getFqlResultSet().castToListOf(TestAccount.class); Collection<UserAccount> userAccounts = fqlResults.get(1).getFqlResultSet().castToListOf(UserAccount.class); // Use both sets of results to populate our static array of accounts. populateTestAccounts(testAccounts, userAccounts); return; }
From source file:de.dmxcontrol.model.BaseModel.java
protected void SendData(String propertyType, Object valueType, Object value) throws JSONException { JSONArray array = new JSONArray(); for (int i = 0; i < ReceivedData.get().Devices.size(); i++) { if (getEntitySelection().contains(EntityManager.Type.DEVICE, ReceivedData.get().Devices.get(i).getId())) { array.put(ReceivedData.get().Devices.get(i).guid); }/*from ww w. ja va 2 s . c o m*/ } for (int i = 0; i < ReceivedData.get().Groups.size(); i++) { if (getEntitySelection().contains(EntityManager.Type.GROUP, ReceivedData.get().Groups.get(i).getId())) { array.put(ReceivedData.get().Groups.get(i).guid); } } JSONObject o = new JSONObject(); o.put("Type", "PropertyValue"); o.put("GUIDs", array); o.put("PropertyType", propertyType); o.put("ValueType", valueType); o.put("Value", value); ServiceFrontend.get().sendMessage(o.toString().getBytes()); }
From source file:org.skt.runtime.html5apis.Battery.java
/** * Creates a JSONObject with the current battery information * // ww w.ja v a2 s . c om * @param batteryIntent the current battery information * @return a JSONObject containing the battery status information */ private JSONObject getBatteryInfo(Intent batteryIntent) { JSONObject obj = new JSONObject(); try { obj.put("level", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, 0)); obj.put("charging", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_PLUGGED, -1) > 0 ? true : false); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return obj; }
From source file:tv.matchstick.demo.dashboard.DashBoardChannel.java
public final void show(FlintManager apiClient, String user, String info) { try {/* w ww . ja v a 2s . c o m*/ Log.d(TAG, "show: " + info); JSONObject payload = new JSONObject(); payload.put(KEY_COMMAND, KEY_SHOW); payload.put(KEY_USER, user); payload.put(KEY_INFO, info); sendMessage(apiClient, payload.toString()); } catch (JSONException e) { Log.e(TAG, "Cannot create object to show file", e); } }
From source file:tv.matchstick.demo.dashboard.DashBoardChannel.java
public final void join(FlintManager apiClient, String user) { try {/*from ww w . j a v a 2 s. c o m*/ Log.d(TAG, "join: " + user); JSONObject payload = new JSONObject(); payload.put(KEY_COMMAND, KEY_JOIN); payload.put(KEY_USER, user); sendMessage(apiClient, payload.toString()); } catch (JSONException e) { Log.e(TAG, "Cannot create object to show file", e); } }
From source file:tv.matchstick.demo.dashboard.DashBoardChannel.java
/** * Sends a command to leave the current game. *///from ww w.java2 s . c o m public final void leave(FlintManager apiClient, String user) { try { Log.d(TAG, "leave"); JSONObject payload = new JSONObject(); payload.put(KEY_COMMAND, KEY_LEAVE); payload.put(KEY_USER, user); sendMessage(apiClient, payload.toString()); } catch (JSONException e) { Log.e(TAG, "Cannot create object to leave", e); } }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainPoll.java
/** * Parse an announcement.//from w w w .j a v a 2 s . c o m * @param jid service that sent the announcement. * @param xml raw XML of announcement to store in SQLite. * @param root parsed XML root DOM element. * @throws JSONException if a parsing error occurs. */ CapptainPoll(String jid, String xml, Element root) throws JSONException { super(jid, xml, root); mAnswers = new Bundle(); mQuestions = new JSONArray(); NodeList questions = root.getElementsByTagNameNS(REACH_NAMESPACE, "question"); for (int i = 0; i < questions.getLength(); i++) { Element questionE = (Element) questions.item(i); NodeList choicesN = questionE.getElementsByTagNameNS(REACH_NAMESPACE, "choice"); JSONArray choicesJ = new JSONArray(); for (int j = 0; j < choicesN.getLength(); j++) { Element choiceE = (Element) choicesN.item(j); JSONObject choiceJ = new JSONObject(); choiceJ.put("id", choiceE.getAttribute("id")); choiceJ.put("title", XmlUtil.getText(choiceE)); choiceJ.put("default", Boolean.parseBoolean(choiceE.getAttribute("default"))); choicesJ.put(choiceJ); } JSONObject questionJ = new JSONObject(); questionJ.put("id", questionE.getAttribute("id")); questionJ.put("title", XmlUtil.getTagText(questionE, "title", null)); questionJ.put("choices", choicesJ); mQuestions.put(questionJ); } }
From source file:com.plant42.log4j.layouts.JSONLayout.java
/** * Converts LoggingEvent Throwable to JSON object * @param json/*from w w w .ja v a 2 s. c om*/ * @param event * @throws JSONException */ protected void writeThrowable(JSONObject json, LoggingEvent event) throws JSONException { ThrowableInformation ti = event.getThrowableInformation(); if (ti != null) { Throwable t = ti.getThrowable(); JSONObject throwable = new JSONObject(); throwable.put("message", t.getMessage()); throwable.put("className", t.getClass().getCanonicalName()); List<JSONObject> traceObjects = new ArrayList<JSONObject>(); for (StackTraceElement ste : t.getStackTrace()) { JSONObject element = new JSONObject(); element.put("class", ste.getClassName()); element.put("method", ste.getMethodName()); element.put("line", ste.getLineNumber()); element.put("file", ste.getFileName()); traceObjects.add(element); } json.put("stackTrace", traceObjects); json.put("throwable", throwable); } }
From source file:com.plant42.log4j.layouts.JSONLayout.java
/** * Converts basic LogginEvent properties to JSON object * @param json//w w w.ja va 2 s.c om * @param event * @throws JSONException */ protected void writeBasic(JSONObject json, LoggingEvent event) throws JSONException { json.put("threadName", event.getThreadName()); json.put("level", event.getLevel().toString()); json.put("timestamp", event.getTimeStamp()); json.put("message", event.getMessage()); json.put("logger", event.getLoggerName()); }