Example usage for org.json JSONObject toString

List of usage examples for org.json JSONObject toString

Introduction

In this page you can find the example usage for org.json JSONObject toString.

Prototype

public String toString() 

Source Link

Document

Make a JSON text of this JSONObject.

Usage

From source file:old.server.packet.PacketFactory.java

public static Packet make(final ENUM_CLIENT_TYPE client_type, final String msg) throws JSONException {
    // Update (?) msg
    final JSONObject jo = new JSONObject();

    jo.put(CommonPacketConsts.CLIENT_TYPE, client_type.ordinal());
    jo.put(CommonPacketConsts.ACTION_TYPE, ACTION_UPDATE.ordinal());
    jo.put(CommonPacketConsts.MESSAGE, msg);

    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 ENUM_MOVE_DIRECTION move_direction)
        throws JSONException {
    // Update direction
    final JSONObject jo = new JSONObject();

    jo.put(CommonPacketConsts.CLIENT_TYPE, client_type.ordinal());
    jo.put(CommonPacketConsts.ACTION_TYPE, ACTION_UPDATE.ordinal());
    jo.put(CommonPacketConsts.MOVE_DIRECTION, move_direction.ordinal());

    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) throws JSONException {
    // Ping packet
    final JSONObject jo = new JSONObject();

    jo.put(CommonPacketConsts.CLIENT_TYPE, client_type.ordinal());
    jo.put(CommonPacketConsts.ACTION_TYPE, ACTION_PING.ordinal());

    final Packet packet = new Packet(jo.toString());

    return packet;
}

From source file:com.google.cast.samples.games.gamedebugger.DebuggerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mCastConnectionManager = GameDebuggerApplication.getInstance().getCastConnectionManager();

    // Inflate the layout for this fragment.
    View view = inflater.inflate(R.layout.debugger_fragment, container, false);

    mTextViewApplicationName = (TextView) view.findViewById(R.id.application_name);
    mTextViewMaxPlayers = (TextView) view.findViewById(R.id.max_players);
    mTextViewLobbyState = (TextView) view.findViewById(R.id.lobby_state);
    mTextViewGameplayState = (TextView) view.findViewById(R.id.gameplay_state);
    mTextViewGameStatusText = (TextView) view.findViewById(R.id.game_status_text);
    mTextViewGameData = (TextView) view.findViewById(R.id.game_data);
    mTextViewLastGameMessagePlayerId = (TextView) view.findViewById(R.id.last_game_message_player_id);
    mTextViewLastGameMessage = (TextView) view.findViewById(R.id.last_game_message);

    mAddPlayerButton = (Button) view.findViewById(R.id.button_add_player);
    mAddPlayerButton.setOnClickListener(new OnClickListener() {
        @Override/*from  ww  w .  ja  v  a2  s.  c  o m*/
        public void onClick(View v) {
            if (!GameDebuggerApplication.getInstance().getRequestInProgress()) {
                mAddPlayerButton.setEnabled(false);

                PendingResult<GameManagerResult> pendingResult = mCastConnectionManager.getGameManagerClient()
                        .sendPlayerAvailableRequest(null, null);
                pendingResult.setResultCallback(new ResultCallback<GameManagerResult>() {
                    @Override
                    public void onResult(GameManagerResult result) {
                        if (!result.getStatus().isSuccess()) {
                            new AlertDialog.Builder(getActivity())
                                    .setMessage(result.getStatus().getStatusMessage())
                                    .setTitle(R.string.error_dialog_title_add_player).create().show();
                        }
                        GameDebuggerApplication.getInstance().setRequestInProgress(false);
                        mAddPlayerButton.setEnabled(mCastConnectionManager.isConnectedToReceiver());
                    }
                });
            }
        }
    });

    mDisconnectButton = (Button) view.findViewById(R.id.button_disconnect);
    mDisconnectButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mCastConnectionManager.disconnectFromReceiver(true);
        }
    });

    mListViewPlayers = (ListView) view.findViewById(R.id.player_list);
    mPlayerListAdapter = new PlayerElementAdapter(getActivity());
    mListViewPlayers.setAdapter(mPlayerListAdapter);
    mListViewPlayers.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View view, MotionEvent event) {
            return false;
        }
    });

    GameManagerClient gameManagerClient = mCastConnectionManager.getGameManagerClient();
    if (mCastConnectionManager.isConnectedToReceiver()) {
        GameManagerState state = gameManagerClient.getCurrentState();
        mTextViewApplicationName.setText(state.getApplicationName());
        mTextViewMaxPlayers.setText(Integer.toString(state.getMaxPlayers()));
        mTextViewLobbyState.setText(getLobbyStateName(state.getLobbyState()));
        mTextViewGameplayState.setText(getGameplayStateName(state.getGameplayState()));
        mTextViewGameStatusText.setText(state.getGameStatusText());

        JSONObject gameData = state.getGameData();
        String gameDataText = gameData != null ? gameData.toString() : "";
        mTextViewGameData.setText(gameDataText);
    }
    mAddPlayerButton.setEnabled(true);
    mDisconnectButton.setEnabled(true);
    mPlayerListAdapter.notifyDataSetChanged();
    setListViewHeightBasedOnChildren(mListViewPlayers);
    return view;
}

From source file:edu.stanford.junction.api.activity.JunctionExtra.java

public void test() {
    JunctionActor actor = new JunctionActor("unittest") {
        @Override/*www .j a va  2  s.co m*/
        public void onMessageReceived(MessageHeader header, JSONObject message) {
            System.out.println(message.toString());
        }

        @Override
        public List<JunctionExtra> getInitialExtras() {
            List<JunctionExtra> extras = new ArrayList<JunctionExtra>();
            extras.add(JunctionExtra.this);
            return extras;
        }
    };

    try {
        // todo: registeredextras here
        SwitchboardConfig config = new XMPPSwitchboardConfig("prpl.stanford.edu");
        JunctionMaker.getInstance(config).newJunction(new URI("junction://prpl.stanford.edu/junit-test"),
                actor);
        synchronized (this) {
            this.wait();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.example.vendrisample.HelloEffects.java

License:asdf

@Override
public void onDrawFrame(final GL10 gl) {
    if (!mInitialized) {
        // Only need to do this once
        mEffectContext = EffectContext.createWithCurrentGlContext();
        mTexRenderer.init();/*from w w  w.  j ava  2  s . com*/
        loadTextures();
        mInitialized = true;
    }
    if (mCurrentEffect != R.id.none) {
        // if an effect is chosen initialize it and apply it to the texture
        initEffect();
        applyEffect();

        // manual play request (bypasses or works in addition to triggers)
        //            String json = "{\"adTags\":[\"http://ad3.liverail.com/?LR_PUBLISHER_ID=1331&LR_CAMPAIGN_ID=229&LR_SCHEMA=vast2\"],\"width\":640,\"height\":480,\"minWidth\":300,\"minHeight\":34,\"retry\":0,\"theme\":\"light\",\"autoplay\":true,\"volume\":0.7,\"controls\":{\"play\":true,\"volume\":true,\"mute\":true,\"progress\":true},\"map\":[{\"name\":\"asdf\",\"callback\":\"{vendriVar}\"}],\"events\":[{\"name\":\"adFinished\",\"callback\":\"helloWorld\"}],\"preferredType\":\"html5\",\"constraints\":{\"startTime\":3,\"playTime\":false},\"bitrate\":{\"check\":true,\"default\":600,\"async\":false},\"audioClickthrough\":false,\"debug\":false}";
        String json = "{}";
        try {

            JSONObject obj = new JSONObject(json);

            Vendri.play(obj, 6);
            Log.d("My App", obj.toString());

        } catch (Throwable t) {
            Log.e("My App", "Could not parse malformed JSON: " + json + "");
        }

    }
    renderResult();
}

From source file:org.wso2.carbon.connector.clevertim.CreateCase.java

/**
 * Create JSON request for CreateCase.//w  ww . j av  a2  s .  c  om
 *
 * @return JSON payload.
 * @throws JSONException thrown when parsing JSON String.
 */
private String getJsonPayload() throws JSONException {

    JSONObject jsonPayload = new JSONObject();

    String name = (String) messageContext.getProperty(Constants.NAME);
    if (name != null && !name.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.NAME, name);
    }
    String description = (String) messageContext.getProperty(Constants.DESCRIPTION);
    if (description != null && !description.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.DESCRIPTION, description);
    }
    String tags = (String) messageContext.getProperty(Constants.TAGS);
    if (tags != null && !tags.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.TAGS, new JSONArray(tags));
    }
    String leadUser = (String) messageContext.getProperty(Constants.LEAD_USER);
    if (leadUser != null && !leadUser.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.LEAD_USER, leadUser);
    }
    String customer = (String) messageContext.getProperty(Constants.CUSTOMER);
    if (customer != null && !customer.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.CUSTOMER, customer);
    }
    String customFields = (String) messageContext.getProperty(Constants.CUSTOM_FIELDS);
    if (customFields != null && !customFields.isEmpty()) {

        jsonPayload.put(Constants.JSONKeys.CUSTOM_FIELD, new JSONObject(customFields));
    }

    return jsonPayload.toString();

}

From source file:game.Clue.JerseyClient.java

public void requestLogintoServer(String name) {

    try {//from   w  w w  .  ja v  a2s . co  m
        for (int i = 0; i < 6; i++) {
            JSONObject jsonObject = new JSONObject(name);

            URL url = new URL(
                    "http://ec2-54-165-198-60.compute-1.amazonaws.com:8080/CluelessServer/webresources/service/player"
                            + i);
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
            //setDoOutput(true);
            connection.setRequestProperty("PUT", "application/json");
            connection.setConnectTimeout(5000);
            connection.setReadTimeout(5000);

            OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
            out.write(jsonObject.toString());

            System.out.println("Sent PUT message for logging into server");
            out.close();
        }
    } catch (Exception e) {
        e.printStackTrace();

    }

}

From source file:game.Clue.JerseyClient.java

public void sendPUT(String name) {
    System.out.println("SendPUT method called");
    try {//from   ww  w.  j  a  va2s.  co  m
        JSONObject jsonObject = new JSONObject("{name:" + name + "}");

        URL url = new URL(
                "http://ec2-54-165-198-60.compute-1.amazonaws.com:8080/CluelessServer/webresources/service/game/player1");
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        //setDoOutput(true);
        connection.setRequestProperty("PUT", "application/json");

        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);

        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
        out.write(jsonObject.toString());

        System.out.println("Sent PUT message to server");
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:game.Clue.JerseyClient.java

public void sendPOST() {
    System.out.println("POST method called");
    try {/*from  ww w  .j  a v  a2s  .c  om*/

        JSONObject jsonObject = new JSONObject("{player:Brian}");
        URL url = new URL(
                "http://ec2-54-165-198-60.compute-1.amazonaws.com:8080/CluelessServer/webresources/service/game/");
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        //setDoOutput(true);
        connection.setRequestProperty("POST", "application/json");
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);

        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
        System.out.println(jsonObject.toString());
        out.write("{" + jsonObject.toString());

        System.out.println("Sent PUT message to server");
        out.close();

    } catch (Exception e) {
        System.out.println("\nError while calling REST POST Service");
        System.out.println(e);
    }

}