List of usage examples for org.json JSONArray JSONArray
public JSONArray()
From source file:com.mobage.air.extension.social.jp.Textdata_getEntries.java
@Override public FREObject call(final FREContext context, FREObject[] args) { try {// w w w .j a v a2 s . co m ArgsParser a = new ArgsParser(args); final String groupName = a.nextString(); final ArrayList<String> entryIds = a.nextStringArrayList(); final String onSuccessId = a.nextString(); final String onErrorId = a.nextString(); a.finish(); com.mobage.android.social.jp.Textdata.OnGetEntriesComplete cb = new com.mobage.android.social.jp.Textdata.OnGetEntriesComplete() { @Override public void onSuccess(ArrayList<com.mobage.android.social.jp.Textdata.TextdataEntry> entries) { try { JSONArray args = new JSONArray(); JSONArray jsonEntries = new JSONArray(); for (com.mobage.android.social.jp.Textdata.TextdataEntry entry : entries) { jsonEntries.put(Convert.jpTextdataEntryToJSON(entry)); } args.put(jsonEntries); Dispatcher.dispatch(context, onSuccessId, args); } catch (Exception e) { Dispatcher.exception(context, e); } } @Override public void onError(Error error) { Dispatcher.dispatch(context, onErrorId, error); } }; com.mobage.android.social.jp.Textdata.getEntries(groupName, entryIds, cb); } catch (Exception e) { Dispatcher.exception(context, e); } return null; }
From source file:org.jabsorb.ng.serializer.impl.SetSerializer.java
@Override public Object marshall(final SerializerState state, final Object p, final Object o) throws MarshallException { final Set<?> set = (Set<?>) o; final JSONObject obj = new JSONObject(); final JSONArray setdata = new JSONArray(); if (ser.getMarshallClassHints()) { try {/*from ww w . j a v a 2s . c om*/ obj.put("javaClass", o.getClass().getName()); } catch (final JSONException e) { throw new MarshallException("javaClass not found!", e); } } try { obj.put("set", setdata); state.push(o, setdata, "set"); } catch (final JSONException e) { throw new MarshallException("Could not set 'set': " + e.getMessage(), e); } Object value = null; int idx = 0; final Iterator<?> i = set.iterator(); try { while (i.hasNext()) { value = i.next(); final Object json = ser.marshall(state, setdata, value, idx); // omit the object entirely if it's a circular reference or // duplicate // it will be regenerated in the fixups phase if (JSONSerializer.CIRC_REF_OR_DUPLICATE != json) { setdata.put(idx, json); } idx++; } } catch (final MarshallException e) { throw new MarshallException("set value " + value + " " + e.getMessage(), e); } catch (final JSONException e) { throw new MarshallException("set value " + value + " " + e.getMessage(), e); } finally { state.pop(); } return obj; }
From source file:Logica.SesionWeb.java
@Override public void notificarUsuariosLogeados(HashMap<String, Usuario> usuariosConectados) { try {//from w w w . j a v a 2s . c o m if (sesion.isOpen()) { JSONObject objetoJSON = new JSONObject(); JSONArray usuarios = new JSONArray(); for (Map.Entry<String, Usuario> entry : usuariosConectados.entrySet()) { String nick = entry.getKey(); usuarios.put(nick); } objetoJSON.put("usuarios", usuarios); objetoJSON.append("tipo", "CONTACTOS"); sesion.getBasicRemote().sendText(objetoJSON.toString()); } } catch (IOException ex) { Logger.getLogger(SesionWeb.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.comcast.oscar.sql.queries.DocsisSqlQuery.java
/** * /*from w w w . j a v a 2 s. c o m*/ * @param iCableLabsConfigType * @return JSONArray * @see com.comcast.oscar.dictionary.Dictionary#getAllTlvDefinition(int) */ public JSONArray getAllTlvDefinition(int iCableLabsConfigType) { JSONArray jsonArrTlvDictionary = new JSONArray(); if (Constants.CONFIGURATION_FILE_TYPE_DOCSIS == iCableLabsConfigType) { for (int tlvCounter = Constants.DOCSIS_TLV_MIN; tlvCounter <= Constants.DOCSIS_TLV_MAX; tlvCounter++) { if (debug) { System.out .println("+------------------------------------------------------------------------+"); System.out.println("TLV: " + tlvCounter + " -> JSON-TLV-DICT: " + getTlvDefinition(tlvCounter)); } } } else if (ConfigurationFileTypeConstants.PKT_CABLE_10_CONFIGURATION_TYPE == iCableLabsConfigType) { } else if (ConfigurationFileTypeConstants.PKT_CABLE_15_CONFIGURATION_TYPE == iCableLabsConfigType) { } else if (ConfigurationFileTypeConstants.PKT_CABLE_20_CONFIGURATION_TYPE == iCableLabsConfigType) { } return jsonArrTlvDictionary; }
From source file:com.comcast.oscar.sql.queries.DocsisSqlQuery.java
/** * /*from www . j a va2s . co m*/ * @param iRowID * @param iParentID * @param aliTlvEncodeHistory * @return JSONObject * @throws JSONException */ private JSONObject recursiveTlvDefinitionBuilder(Integer iRowID, Integer iParentID, ArrayList<Integer> aliTlvEncodeHistory) throws JSONException { Statement parentCheckStatement = null, getRowDefinitionStatement = null; ResultSet resultSetParentCheck = null, resultSetGetRowDefinition = null; aliTlvEncodeHistory.add(getTypeFromRowID(iParentID)); String sqlQuery; JSONObject tlvJsonObj = null; // This query will check for child rows that belong to a parent row sqlQuery = "SELECT " + " ID ," + " TYPE ," + " TLV_NAME," + " PARENT_ID " + "FROM " + " DOCSIS_TLV_DEFINITION " + "WHERE " + " PARENT_ID = '" + iRowID + "'"; try { //Create statement parentCheckStatement = sqlConnection.createStatement(); //Get Result Set of Query resultSetParentCheck = parentCheckStatement.executeQuery(sqlQuery); } catch (SQLException e) { e.printStackTrace(); } /* ****************************************************************************************************** * If resultSet return an empty, this means that the row does not have a child and is not a Major TLV * *****************************************************************************************************/ try { if ((SqlConnection.getRowCount(resultSetParentCheck) == 0) && (iParentID != MAJOR_TLV)) { // This query will check for child rows that belong to a parent row sqlQuery = "SELECT * FROM " + " DOCSIS_TLV_DEFINITION " + " WHERE ID = '" + iRowID + "'"; //Create statement to get Rows from ROW ID's getRowDefinitionStatement = sqlConnection.createStatement(); //Get Result Set resultSetGetRowDefinition = getRowDefinitionStatement.executeQuery(sqlQuery); //Advance to next index in result set, this is needed resultSetGetRowDefinition.next(); /************************************************* * Assemble JSON OBJECT *************************************************/ tlvJsonObj = new JSONObject(); tlvJsonObj.put(Dictionary.TYPE, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TYPE)); tlvJsonObj.put(Dictionary.TLV_NAME, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TLV_NAME)); tlvJsonObj.put(Dictionary.LENGTH_MIN, resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MIN)); tlvJsonObj.put(Dictionary.LENGTH_MAX, resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MAX)); tlvJsonObj.put(Dictionary.SUPPORTED_VERSIONS, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_SUPPORTED_VERSIONS)); tlvJsonObj.put(Dictionary.DATA_TYPE, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_DATA_TYPE)); tlvJsonObj.put(Dictionary.ARE_SUBTYPES, false); tlvJsonObj.put(Dictionary.BYTE_LENGTH, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_BYTE_LENGTH)); aliTlvEncodeHistory.add(resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_TYPE)); tlvJsonObj.put(Dictionary.PARENT_TYPE_LIST, aliTlvEncodeHistory); if (debug) System.out.println(tlvJsonObj.toString()); } else if (iParentID == MAJOR_TLV) { // This query will check for child rows that belong to a parent row sqlQuery = "SELECT * FROM " + " DOCSIS_TLV_DEFINITION " + " WHERE ID = '" + iRowID + "'"; getRowDefinitionStatement = sqlConnection.createStatement(); resultSetGetRowDefinition = getRowDefinitionStatement.executeQuery(sqlQuery); resultSetGetRowDefinition.next(); /************************************************* * Assemble JSON OBJECT *************************************************/ tlvJsonObj = new JSONObject(); tlvJsonObj.put(Dictionary.TYPE, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TYPE)); tlvJsonObj.put(Dictionary.TLV_NAME, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TLV_NAME)); tlvJsonObj.put(Dictionary.LENGTH_MIN, resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MIN)); tlvJsonObj.put(Dictionary.LENGTH_MAX, resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MAX)); tlvJsonObj.put(Dictionary.SUPPORTED_VERSIONS, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_SUPPORTED_VERSIONS)); tlvJsonObj.put(Dictionary.DATA_TYPE, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_DATA_TYPE)); tlvJsonObj.put(Dictionary.ARE_SUBTYPES, false); tlvJsonObj.put(Dictionary.BYTE_LENGTH, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_BYTE_LENGTH)); aliTlvEncodeHistory.add(resultSetGetRowDefinition.getInt("TYPE")); tlvJsonObj.put(Dictionary.PARENT_TYPE_LIST, aliTlvEncodeHistory); if (debug) System.out.println(tlvJsonObj.toString()); } if (SqlConnection.getRowCount(resultSetParentCheck) > 0) { // This query will check for child rows that belong to a parent row sqlQuery = "SELECT " + " TYPE , " + " TLV_NAME," + " PARENT_ID" + " FROM " + " DOCSIS_TLV_DEFINITION " + " WHERE ID = '" + iRowID + "'"; try { Integer iParentIdTemp = null; JSONArray tlvJsonArray = new JSONArray(); while (resultSetParentCheck.next()) { iParentIdTemp = resultSetParentCheck.getInt(Dictionary.DB_TBL_COL_PARENT_ID); ArrayList<Integer> aliTlvEncodeHistoryNext = new ArrayList<Integer>(); aliTlvEncodeHistoryNext.addAll(aliTlvEncodeHistory); if (debug) System.out.println("aliTlvEncodeHistoryNext: " + aliTlvEncodeHistoryNext); aliTlvEncodeHistoryNext.remove(aliTlvEncodeHistoryNext.size() - 1); //Keep processing each row using recursion until you get to to the bottom of the tree tlvJsonArray.put( recursiveTlvDefinitionBuilder(resultSetParentCheck.getInt(Dictionary.DB_TBL_COL_ID), iParentIdTemp, aliTlvEncodeHistoryNext)); } //Get Parent Definition tlvJsonObj = getRowDefinitionViaRowId(iParentIdTemp); tlvJsonObj.put(Dictionary.SUBTYPE_ARRAY, tlvJsonArray); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return tlvJsonObj; }
From source file:uk.ac.imperial.presage2.web.SimulationsTreeServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logRequest(req);/*from w w w .j a v a2s. co m*/ // check which node to check from String node = req.getParameter("node"); if (node == null) { resp.setStatus(400); return; } long nodeId; if (node.equalsIgnoreCase("root")) { nodeId = 0; } else { try { nodeId = Long.parseLong(node); } catch (NumberFormatException e) { resp.setStatus(400); return; } } List<PersistentSimulation> sims = new LinkedList<PersistentSimulation>(); for (Long simId : this.sto.getSimulations()) { PersistentSimulation sim = this.sto.getSimulationById(simId); PersistentSimulation parent = sim.getParentSimulation(); if ((nodeId == 0 && parent == null) || (parent != null && nodeId > 0 && parent.getID() == nodeId)) { sims.add(sim); } } // build JSON response try { JSONObject jsonResp = new JSONObject(); JSONArray jsonSims = new JSONArray(); for (PersistentSimulation sim : sims) { jsonSims.put(SimulationServlet.simulationToJSON(sim)); } jsonResp.put("data", jsonSims); jsonResp.put("success", true); resp.setStatus(200); resp.getWriter().write(jsonResp.toString()); } catch (JSONException e) { resp.setStatus(500); } }
From source file:com.basho.riak.client.http.mapreduce.filter.ToUpperFilter.java
public JSONArray toJson() { JSONArray filter = new JSONArray(); filter.put("to_upper"); return filter; }
From source file:org.exoplatform.social.portlet.UISpacesToolBarPortlet.java
private JSONArray getChildrenAsJSON(UserNode userNode) throws Exception { if (userNode == null) { return null; }// w w w . j a v a2s. co m NodeChangeQueue<UserNode> queue = new NodeChangeQueue<UserNode>(); //Scope.CHILDREN ??? SpaceUtils.getUserPortal().updateNode(userNode, toolbarScope, queue); for (NodeChange<UserNode> change : queue) { if (change instanceof NodeChange.Removed) { UserNode deletedNode = ((NodeChange.Removed<UserNode>) change).getTarget(); if (hasRelationship(deletedNode, userNode)) { return null; } } } Collection<UserNode> childs = userNode.getChildren(); JSONArray jsChilds = new JSONArray(); WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); MimeResponse res = context.getResponse(); for (UserNode child : childs) { jsChilds.put(toJSON(child, userNode.getNavigation().getKey().getName(), res)); } return jsChilds; }
From source file:org.exoplatform.social.portlet.UISpacesToolBarPortlet.java
protected JSONObject toJSON(UserNode node, String navId, MimeResponse res) throws Exception { JSONObject json = new JSONObject(); String nodeId = node.getId(); json.put("label", node.getEncodedResolvedLabel()); json.put("hasChild", node.getChildrenCount() > 0); json.put("isSelected", nodeId.equals(getSelectedNode().getId())); json.put("icon", node.getIcon()); ResourceURL rsURL = res.createResourceURL(); rsURL.setResourceID(res.encodeURL(getResourceIdFromNode(node, navId))); json.put("getNodeURL", rsURL.toString()); json.put("actionLink", Util.getPortalRequestContext().getPortalURI() + node.getURI()); JSONArray childs = new JSONArray(); for (UserNode child : node.getChildren()) { childs.put(toJSON(child, navId, res)); }//from w w w .j a v a 2 s. co m json.put("childs", childs); return json; }
From source file:com.tonikorin.cordova.plugin.LocationProvider.LocationService.java
private void updateLocateHistory(JSONObject messageIn, boolean blocked, String msgType, String time) throws JSONException { // Read current history SharedPreferences sp = myContext.getSharedPreferences(LocationService.PREFS_NAME, Context.MODE_PRIVATE); String historyJsonStr = sp.getString(LocationService.HISTORY_NAME, "{}"); JSONObject history = new JSONObject(historyJsonStr); if (CHAT.equals(msgType)) { // CHAT history, save hole message JSONArray chatMessages = history.optJSONArray("chatMessages"); if (chatMessages == null) chatMessages = new JSONArray(); //Log.d(TAG, "CHAT history TIME: " + time); messageIn.put("time", Long.parseLong(time)); chatMessages.put(messageIn.toString()); if (chatMessages.length() > 100) chatMessages.remove(0); // store only last 100 chat messages history.put("chatMessages", chatMessages); } else {// Current LOCATE String member = messageIn.optString("memberName", ""); if (blocked) member = "\u2717 " + member; JSONObject updateStatus = new JSONObject(); updateStatus.put("member", member); updateStatus.put("team", messageIn.optString("teamId", "")); updateStatus.put("date", getDateAndTimeString(System.currentTimeMillis())); updateStatus.put("target", messageIn.optString("target", "")); history.put("updateStatus", updateStatus); // History LOCATE lines... JSONArray historyLines = history.optJSONArray("lines"); if (historyLines == null) historyLines = new JSONArray(); String target;/* w w w.j a v a 2 s .com*/ if (updateStatus.getString("target").equals("")) target = updateStatus.optString("team"); else target = updateStatus.optString("target"); String historyLine = updateStatus.getString("member") + " (" + target + ") " + updateStatus.getString("date") + "\n"; historyLines.put(historyLine); if (historyLines.length() > 200) historyLines.remove(0); // store only last 200 locate queries history.put("lines", historyLines); } // Save new history SharedPreferences.Editor editor = sp.edit(); editor.putString(LocationService.HISTORY_NAME, history.toString()); editor.commit(); //Log.d(TAG, "history:" + history.toString()); }