List of usage examples for org.json JSONObject toString
public String toString()
From source file:org.eclipse.orion.server.tests.servlets.git.GitCherryPickTest.java
private static WebRequest getPostGitCherryPickRequest(String location, String toCherryPick) throws JSONException, UnsupportedEncodingException { String requestURI = toAbsoluteURI(location); JSONObject body = new JSONObject(); body.put(GitConstants.KEY_CHERRY_PICK, toCherryPick); WebRequest request = new PostMethodWebRequest(requestURI, IOUtilities.toInputStream(body.toString()), "UTF-8"); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request);/*w w w. ja v a 2 s .c om*/ return request; }
From source file:com.ecml.MidiOptions.java
/** Convert this MidiOptions object into a JSON string. */ public String toJson() { try {//from w w w . ja va 2 s .co m JSONObject json = new JSONObject(); JSONArray jsonTracks = new JSONArray(); for (boolean value : tracks) { jsonTracks.put(value); } JSONArray jsonMute = new JSONArray(); for (boolean value : mute) { jsonMute.put(value); } JSONArray jsonInstruments = new JSONArray(); for (int value : instruments) { jsonInstruments.put(value); } if (time != null) { JSONObject jsonTime = new JSONObject(); jsonTime.put("numerator", time.getNumerator()); jsonTime.put("denominator", time.getDenominator()); jsonTime.put("quarter", time.getQuarter()); jsonTime.put("tempo", time.getTempo()); json.put("time", jsonTime); } json.put("versionCode", 7); json.put("tracks", jsonTracks); json.put("mute", jsonMute); json.put("instruments", jsonInstruments); json.put("useDefaultInstruments", useDefaultInstruments); json.put("scrollVert", scrollVert); json.put("showPiano", showPiano); json.put("showNoteColors", showNoteColors); json.put("showLyrics", showLyrics); json.put("delay", delay); json.put("twoStaffs", twoStaffs); json.put("showNoteLetters", showNoteLetters); json.put("transpose", transpose); json.put("key", key); json.put("combineInterval", combineInterval); json.put("shade1Color", shade1Color); json.put("shade2Color", shade2Color); json.put("showMeasures", showMeasures); json.put("playMeasuresInLoop", playMeasuresInLoop); json.put("playMeasuresInLoopStart", playMeasuresInLoopStart); json.put("playMeasuresInLoopEnd", playMeasuresInLoopEnd); return json.toString(); } catch (JSONException e) { return null; } catch (NullPointerException e) { return null; } }
From source file:blink.Message.java
/** * a Message object that represents a message to be sent * @param timestamp when a message was created * @param text the actual content of the message * @param userId the id number for the user sending the message *//*from w w w . j a v a 2 s . c o m*/ public Message(long timestamp, String text, int userId) { this.timestamp = timestamp; this.text = text; this.userId = userId; this.type = "message"; JSONObject json = new JSONObject(); try { json.put("timestamp", timestamp); json.put("content", text); json.put("type", "message"); } catch (JSONException ex) { Logger.getLogger(Message.class.getName()).log(Level.SEVERE, null, ex); } this.json = json.toString(); }
From source file:com.cmgapps.android.util.CMGAppRater.java
private static String ratePreferenceToString(SharedPreferences pref) { JSONObject thiz = new JSONObject(); try {//from ww w . j ava 2s.c o m thiz.put(DECLINED_RATE, pref.getBoolean(DECLINED_RATE, false)); thiz.put(APP_RATED, pref.getBoolean(APP_RATED, false)); thiz.put(TRACKING_VERSION, pref.getInt(TRACKING_VERSION, -1)); thiz.put(FIRST_USE, SimpleDateFormat.getDateTimeInstance().format(new Date(pref.getLong(FIRST_USE, 0L)))); thiz.put(USE_COUNT, pref.getInt(USE_COUNT, 0)); thiz.put(REMIND_LATER_DATE, SimpleDateFormat.getDateTimeInstance().format(new Date(pref.getLong(REMIND_LATER_DATE, 0L)))); } catch (JSONException exc) { LOGE(TAG, "Error creating JSON Object", exc); } return thiz.toString(); }
From source file:org.openmrs.mobile.listeners.visit.VisitTypeListener.java
@Override public void onResponse(JSONObject response) { mLogger.d(response.toString()); try {// w ww .jav a 2 s . c o m JSONArray visitTypesObj = response.getJSONArray("results"); String visitTypeUUID = ((JSONObject) visitTypesObj.get(0)).getString("uuid"); OpenMRS.getInstance().setVisitTypeUUID(visitTypeUUID); } catch (JSONException e) { mLogger.d(e.toString()); } }
From source file:org.rapidandroid.activity.FormCreator.java
private void saveState() { // TODO Auto-generated method stub // this.d//from w w w .j a va2s.co m JSONObject savedstate = new JSONObject(); EditText etxFormName = (EditText) findViewById(R.id.etx_formname); EditText etxFormPrefix = (EditText) findViewById(R.id.etx_formprefix); EditText etxDescription = (EditText) findViewById(R.id.etx_description); // ListView lsv = (ListView) findViewById(R.id.lsv_createfields); try { savedstate.put(STATE_FORMNAME, etxFormName.getText().toString()); savedstate.put(STATE_PREFIX, etxFormPrefix.getText().toString()); savedstate.put(STATE_DESC, etxDescription.getText().toString()); savedstate.put(STATE_PARSER, mChosenParser.getName()); if (mCurrentFields != null) { int numFields = this.mCurrentFields.size(); for (int i = 0; i < numFields; i++) { Field f = mCurrentFields.get(i); JSONObject fieldobj = new JSONObject(); fieldobj.put(AddField.ResultConstants.RESULT_KEY_FIELDNAME, f.getName()); fieldobj.put(AddField.ResultConstants.RESULT_KEY_DESCRIPTION, f.getDescription()); fieldobj.put(AddField.ResultConstants.RESULT_KEY_FIELDTYPE_ID, ((SimpleFieldType) f.getFieldType()).getId()); savedstate.put("Field" + i, fieldobj); } } getIntent().putExtra("current_form", savedstate.toString()); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); Log.d("FormCreator", e1.getMessage()); } }
From source file:net.jmhertlein.mcanalytics.api.request.PasswordResetRequest.java
@Override public String toJSON() { JSONObject ret = new JSONObject(); ret.put("id", getRequestId()); ret.put("type", RequestType.PASSWORD_RESET); ret.put("username", username); ret.put("old", oldPass); ret.put("new", newPass); return ret.toString(); }
From source file:old.server.packet.PacketFactory.java
public static Packet make(final PACKET_TYPE packet_type, final ENUM_CLIENT_TYPE client_type) throws JSONException { // Disconnect player, result success, result fail final JSONObject jo = new JSONObject(); jo.put(CommonPacketConsts.CLIENT_TYPE, client_type); switch (PACKET_TYPE.values()[packet_type.ordinal()]) { case PACKET_TYPE_DISCONNECT_PLAYER: { jo.put(CommonPacketConsts.ACTION_TYPE, CommonPacketConsts.ENUM_ACTION_TYPE.ACTION_UNREGISTER.ordinal()); break;//w w w . j a va2s .c o m } case PACKET_TYPE_RESULT_SUCCESS: { jo.put(CommonPacketConsts.ACTION_TYPE, CommonPacketConsts.ENUM_ACTION_TYPE.ACTION_RESULT.ordinal()); jo.put(CommonPacketConsts.RESULT, CommonPacketConsts.ENUM_RESULT.RESULT_SUCCESS.ordinal()); break; } case PACKET_TYPE_RESULT_FAIL: { jo.put(CommonPacketConsts.ACTION_TYPE, CommonPacketConsts.ENUM_ACTION_TYPE.ACTION_RESULT.ordinal()); jo.put(CommonPacketConsts.RESULT, CommonPacketConsts.ENUM_RESULT.RESULT_FAIL.ordinal()); break; } default: { break; } } final Packet packet = new Packet(jo.toString()); return packet; }
From source file:old.server.packet.PacketFactory.java
public static Packet make(final ENUM_CLIENT_TYPE client_type, final String username, final String sender_host, final int sender_port, final ENUM_PLAYER_ROLE player_role) throws JSONException { // Redirect packet final JSONObject jo = new JSONObject(); jo.put(CommonPacketConsts.CLIENT_TYPE, client_type.ordinal()); jo.put(CommonPacketConsts.ACTION_TYPE, ACTION_REGISTER.ordinal()); jo.put(CommonPacketConsts.ITEM_USERNAME, username); jo.put(CommonPacketConsts.ITEM_HOST, sender_host); jo.put(CommonPacketConsts.ITEM_PORT, sender_port); jo.put(CommonPacketConsts.PLAYER_ROLE, player_role.ordinal()); final Packet packet = new Packet(jo.toString()); return packet; }
From source file:old.server.packet.PacketFactory.java
public static Packet make(final float ball_x, final float ball_y, final float p1_x, final float p1_y, final float p2_x, final float p2_y) throws JSONException { // Update game state final JSONObject jo = new JSONObject(); jo.put(CommonPacketConsts.BALL_POS_X, ball_x); jo.put(CommonPacketConsts.BALL_POS_Y, ball_y); jo.put(CommonPacketConsts.P1_POS_X, p1_x); jo.put(CommonPacketConsts.P1_POS_Y, p1_y); jo.put(CommonPacketConsts.P2_POS_X, p2_x); jo.put(CommonPacketConsts.P2_POS_Y, p2_y); final Packet packet = new Packet(jo.toString()); return packet; }