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:fr.bmartel.android.tictactoe.GameSingleton.java

public void declineChallenge(String challengerId, String challengerName) {

    Log.i(TAG, "send decline challenge request : "
            + RequestBuilder.buildChallengeResponse(DEVICE_ID, challengerName, challengerId));

    JsonObjectRequest jsObjRequest = new JsonObjectRequest(BuildConfig.APP_ROUTE + "/decline_challenge",
            RequestBuilder.buildChallengeResponse(DEVICE_ID, challengerName, challengerId),
            new Response.Listener<JSONObject>() {

                @Override/*from w  w  w  .  j  a  v  a2s  .  c om*/
                public void onResponse(JSONObject response) {

                    Log.i(TAG, "response received decline challenge : " + response.toString());
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO Auto-generated method stub
                    error.printStackTrace();
                }
            });
    jsObjRequest.setShouldCache(false);
    queue.add(jsObjRequest);
}

From source file:fr.bmartel.android.tictactoe.GameSingleton.java

public void sendNextTurn(int segmentNum, String challengerId) {

    Log.i(TAG, "send next turn request : "
            + RequestBuilder.buildNextTurnRequest(DEVICE_ID, segmentNum, challengerId));

    JsonObjectRequest jsObjRequest = new JsonObjectRequest(BuildConfig.APP_ROUTE + "/play",
            RequestBuilder.buildNextTurnRequest(DEVICE_ID, segmentNum, challengerId),
            new Response.Listener<JSONObject>() {

                @Override//  w  ww  .java  2  s .c  o m
                public void onResponse(JSONObject response) {

                    Log.i(TAG, "response received next turn : " + response.toString());
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO Auto-generated method stub
                    error.printStackTrace();
                }
            });
    jsObjRequest.setShouldCache(false);
    queue.add(jsObjRequest);
}

From source file:com.altamiracorp.lumify.twitter.DefaultLumifyTwitterProcessor.java

@Override
public Vertex parseTweet(final String processId, final JSONObject jsonTweet) throws Exception {
    // TODO set visibility
    Visibility visibility = new Visibility("");

    // cache current User
    User user = getUser();/*from   w w w  .java 2  s.c  o m*/

    String tweetText = JSON_TEXT_PROPERTY.getFrom(jsonTweet);
    Date tweetCreatedAt = JSON_CREATED_AT_PROPERTY.getFrom(jsonTweet);
    String tweeterScreenName = JSON_SCREEN_NAME_PROPERTY.getFrom(JSON_USER_PROPERTY.getFrom(jsonTweet));

    // at minimum, the tweet text and user screen name must be set or this object cannot be
    // added to the system as a Tweet
    if (tweetText == null || tweeterScreenName == null || tweeterScreenName.trim().isEmpty()) {
        return null;
    }

    byte[] jsonBytes = jsonTweet.toString().getBytes(TWITTER_CHARSET);
    String rowKey = RowKeyHelper.buildSHA256KeyString(jsonBytes);

    Concept concept = getOntologyRepository().getConceptByName(CONCEPT_TWEET);
    ElementMutation<Vertex> artifactMutation = findOrPrepareArtifactVertex(rowKey);
    CONCEPT_TYPE.setProperty(artifactMutation, concept.getId(), visibility);
    TITLE.setProperty(artifactMutation, tweetText, visibility);
    SOURCE.setProperty(artifactMutation, TWITTER_SOURCE, visibility);
    AUTHOR.setProperty(artifactMutation, tweeterScreenName, visibility);
    MIME_TYPE.setProperty(artifactMutation, TWEET_ARTIFACT_MIME_TYPE, visibility);
    ROW_KEY.setProperty(artifactMutation, rowKey, visibility);
    PROCESS.setProperty(artifactMutation, processId, visibility);

    if (tweetCreatedAt != null) {
        PUBLISHED_DATE.setProperty(artifactMutation, tweetCreatedAt, visibility);
    }

    TEXT.setProperty(artifactMutation, new StreamingPropertyValue(
            new ByteArrayInputStream(tweetText.getBytes(TWITTER_CHARSET)), String.class), visibility);

    setOptionalProps(artifactMutation, jsonTweet, OPTIONAL_TWEET_PROPERTY_MAP, visibility);

    Vertex tweet;
    if (!(artifactMutation instanceof ExistingElementMutation)) {
        tweet = artifactMutation.save();
        getAuditRepository().auditVertexElementMutation(artifactMutation, tweet, processId, user, visibility);
    } else {
        getAuditRepository().auditVertexElementMutation(artifactMutation, null, processId, user, visibility);
        tweet = artifactMutation.save();
    }
    getGraph().flush();

    String tweetId = tweet.getId().toString();
    LOGGER.info("Saved Tweet to Accumulo and as Graph Vertex: %s", tweetId);

    getAuditRepository().auditVertexElementMutation(artifactMutation, tweet, processId, user, visibility);

    return tweet;
}

From source file:com.ws.WS_TCS201.java

@Path("/GetID/{com}")
@JSONP(queryParam = "callback")
@GET//from   w  w  w.  ja v  a2s  .c o m
@Produces({ "application/x-javascript" })
public String GetID(@QueryParam("callback") String callback, @PathParam("com") String com) {
    //JOptionPane.showMessageDialog(null, "??", "Which way?", JOptionPane.INFORMATION_MESSAGE );
    JSONObject obj1 = new JSONObject();
    LinkedList l1 = new LinkedList();
    //JSONArray l1 = new JSONArray();

    PreparedStatement prepStmt = null;

    DateFormat day = new SimpleDateFormat("yyyyMMdd");
    String tmpday = day.format(new java.util.Date());

    try {
        String cSQL = "SELECT tceemp,tcenam FROM TCSTCE "
                + "WHERE tcecom = ? AND ( tceljd=0 OR tceljd + 100 > \"" + tmpday + "\" ) "
                + "ORDER BY tceemp,tcecom ";
        prepStmt = connection.prepareStatement(cSQL);
        prepStmt.setString(1, com);
        ResultSet result = prepStmt.executeQuery();
        ResultSetMetaData rsmd = result.getMetaData();
        int numcols = rsmd.getColumnCount();

        while (result.next()) {
            LinkedHashMap m1 = new LinkedHashMap();
            for (int j = 1; j <= numcols; j++) {
                Object obj = result.getObject(j);
                m1.put(rsmd.getColumnName(j).toString(), obj.toString());
            }
            l1.add(m1);
        }
        obj1.put("record", l1);
    } catch (SQLException e) {
        prepStmt = null;
        e.printStackTrace();
    } catch (Exception e) {
        prepStmt = null;
        e.printStackTrace();
    }
    return obj1.toString();
}

From source file:com.ws.WS_TCS201.java

@Path("/GetTCD")
@JSONP(queryParam = "callback")
@GET/*w  ww. j a va  2 s  .  com*/
@Produces({ "application/x-javascript" })
public String GetTCD(@QueryParam("callback") String callback) {

    JSONObject obj1 = new JSONObject();
    LinkedList l1 = new LinkedList();
    //JSONArray l1 = new JSONArray();

    PreparedStatement prepStmt = null;

    try {
        String cSQL = "SELECT tcctcd,CONCAT(tcctcd,\" - \",trim(tcctxt)) AS name FROM TCSTCC "
                + "WHERE tcctcd NOT IN (\"A\",\"L\",\"N\",\"J\",\"R\",\"E\") " + "ORDER BY tcctcd ";
        prepStmt = connection.prepareStatement(cSQL);
        ResultSet result = prepStmt.executeQuery();
        ResultSetMetaData rsmd = result.getMetaData();
        int numcols = rsmd.getColumnCount();

        while (result.next()) {
            LinkedHashMap m1 = new LinkedHashMap();
            for (int j = 1; j <= numcols; j++) {
                Object obj = result.getObject(j);
                m1.put(rsmd.getColumnName(j).toString(), obj.toString());
            }
            l1.add(m1);
        }
        obj1.put("record", l1);
    } catch (SQLException e) {
        prepStmt = null;
        e.printStackTrace();
    } catch (Exception e) {
        prepStmt = null;
        e.printStackTrace();
    }
    return obj1.toString();
}

From source file:com.ws.WS_TCS201.java

@Path("/GetDETAIL/{com}/{account}")
@JSONP(queryParam = "callback")
@GET// w  w w  .  jav  a2  s.c  om
@Produces({ "application/x-javascript" })
public String GetDETAIL(@QueryParam("callback") String callback, @PathParam("com") String com,
        @PathParam("account") String account) {

    JSONObject obj1 = new JSONObject();
    LinkedList l1 = new LinkedList();

    PreparedStatement prepStmt = null;

    try {
        //

        String cSQL = " SELECT tceemp, tceapd, tceall, tcetkb, tcetkt FROM TCSTCE "
                + " WHERE tcecom= ? AND tceemp= ? " + " ORDER BY tceapd DESC";
        prepStmt = connection.prepareStatement(cSQL);
        prepStmt.setString(1, com);
        prepStmt.setString(2, account);
        ResultSet result = prepStmt.executeQuery();

        if (result.next()) {
            LinkedHashMap m1 = new LinkedHashMap();

            Object obj = result.getObject(2);

            //?
            m1.put("arrive", obj.toString().substring(0, 4) + "/" + obj.toString().substring(4, 6) + "/"
                    + obj.toString().substring(6, 8));

            //
            if (Integer.parseInt(obj.toString()) < 20100913) {
                m1.put("start", "01/01");
            } else {
                m1.put("start", obj.toString().substring(4, 6) + "/" + obj.toString().substring(6, 8));
            }

            //
            obj = result.getObject(3);
            m1.put("allday", obj.toString());

            l1.add(m1);
        }
        obj1.put("base", l1);

        //
        result.close();
        l1.clear();

        cSQL = " SELECT tch.tchyer,CONCAT(tch.tchtcd,\" - \",tcc.tcctxt) AS tcdnam,tch.tchdst,tch.tchded,tch.tchday,tch.tchlst,tch.tchtxt,tch.tchtcd,tch.tchtck, "
                + "        IFNULL(tchgrp.maxtck,\"\") AS maxtck, IFNULL(tchgrp.maxdst,0) AS maxdst "
                + " FROM TCSTCH AS tch "
                + " LEFT JOIN (SELECT DISTINCT tcecom,tceemp,tcenam FROM TCSTCE) AS tce "
                + "        ON tcecom=tchcom AND tce.tceemp=tch.tchemp "
                + " LEFT JOIN (SELECT tcctcd, tcctxt FROM TCSTCC ) AS tcc "
                + "        ON tcc.tcctcd=tch.tchtcd "
                + " LEFT JOIN ( SELECT tchcom,tchemp,tchyer,max(tchtck) AS maxtck,max(tchdst) AS maxdst FROM TCSTCH "
                + "             WHERE tchtcd not in (\"B\",\"T\",\"M\",\"F\",\"W\") "
                + "             GROUP BY tchcom,tchemp,tchyer ) AS tchgrp "
                + "        ON tch.tchcom = tchgrp.tchcom AND tch.tchemp = tchgrp.tchemp "
                + "       AND tch.tchyer = tchgrp.tchyer " + " WHERE tch.tchcom= ? AND tch.tchemp= ? "
                + "   AND tcc.tcctcd NOT IN (\"A\",\"L\",\"R\",\"J\",\"N\") "
                + "   AND tch.tchmrk=\" \" AND tch.tchyer >= 2014 " + " ORDER BY tch.tchemp,tch.tchdst DESC ";
        //"       tchmrk=\" \" AND tchyer >= CONV( SUBSTR(NOW( ),1,4),10,10) -1 " +
        prepStmt = connection.prepareStatement(cSQL);
        prepStmt.setString(1, com);
        prepStmt.setString(2, account);
        result = prepStmt.executeQuery();
        ResultSetMetaData rsmd = result.getMetaData();
        int numcols = rsmd.getColumnCount();

        while (result.next()) {
            LinkedHashMap m1 = new LinkedHashMap();
            for (int j = 1; j <= numcols; j++) {
                Object obj = result.getObject(j);
                m1.put(rsmd.getColumnName(j).toString(), obj.toString());
            }
            Object obj = result.getObject("tchtcd");
            String chk1 = obj.toString();
            obj = result.getObject("tchtck");
            String chk2 = obj.toString();
            obj = result.getObject("tchdst");
            String chk3 = obj.toString();
            obj = result.getObject("maxdst");
            String chk4 = obj.toString();
            if (((chk1.equals("M") || chk1.equals("F") || chk1.equals("W") || chk1.equals("B")
                    || chk1.equals("T")) && chk2.equals("-"))
                    || (!chk1.equals("M") && !chk1.equals("F") && !chk1.equals("W") && !chk1.equals("B")
                            && !chk1.equals("T") && chk3.equals(chk4))) {
                m1.put("edit", "Y");
            } else {
                m1.put("edit", "N");
            }
            l1.add(m1);
        }
        obj1.put("detail", l1);
    } catch (SQLException e) {
        prepStmt = null;
        e.printStackTrace();
    } catch (Exception e) {
        prepStmt = null;
        e.printStackTrace();
    }
    return obj1.toString();
}

From source file:com.ws.WS_TCS201.java

@Path("/Act")
@JSONP(queryParam = "callback")
@POST/*from   ww w  .jav a 2 s  .c om*/
@Produces({ "application/x-javascript" })
public String Act(@QueryParam("callback") String callback, @FormParam("state") String state,
        @FormParam("com") String com, @FormParam("emp") String emp, @FormParam("tcd") String tcd,
        @FormParam("year") String year, @FormParam("strdate") String strdate,
        @FormParam("enddate") String enddate, @FormParam("days") String days,
        @FormParam("comment") String comment, @FormParam("oldstrdate") String oldstrdate,
        @Context HttpServletResponse servletResponse) {

    JSONObject obj1 = new JSONObject();
    LinkedList l1 = new LinkedList();
    String cSQL = "";
    int yeartkb = 0, yeartkt = 0, cnttkb = 0, cnttkt = 0;
    float cntdays = 0, allowdays = 0, tmplst = 0;
    String tmptck = "-";
    String msg = "";
    String yearStartDate = "";

    PreparedStatement prepStmt = null;

    try {
        if (!state.equals("D") && (msg.equals(""))) {
            //
            if (state.equals("I")) {
                oldstrdate = "0";
            }

            //?
            cSQL = " SELECT tceemp, tceapd, tceall, tcetkb, tcetkt FROM TCSTCE "
                    + " WHERE tcecom= ? AND tceemp= ? " + " ORDER BY tceapd DESC";
            prepStmt = connection.prepareStatement(cSQL);
            prepStmt.setString(1, com);
            prepStmt.setString(2, emp);
            ResultSet result = prepStmt.executeQuery();

            if (result.next()) {
                //
                Object obj = result.getObject(3);
                allowdays = Integer.parseInt(obj.toString());
                obj = result.getObject(4);
                yeartkb = Integer.parseInt(obj.toString());
                obj = result.getObject(5);
                yeartkt = Integer.parseInt(obj.toString());

                //***************************************************************
                if (msg.equals("")) {
                    obj = result.getObject(2);
                    yearStartDate = obj.toString();
                    if (Integer.parseInt(yearStartDate) <= 20100913) {
                        //2010.9.13?? 01/01
                        if ((Integer.parseInt(strdate.substring(4)) < Integer.parseInt("0101"))
                                && (Integer.parseInt(enddate.substring(4)) >= Integer.parseInt("0101"))) {
                            msg = "C";
                        }
                    } else {
                        //2010.9.13? ??
                        yearStartDate = year + yearStartDate.substring(4);
                        if ((Integer.parseInt(strdate) < Integer.parseInt(yearStartDate))
                                && (Integer.parseInt(enddate) >= Integer.parseInt(yearStartDate))) {
                            msg = "C";
                        }
                    }
                }
            } else {
                msg = "H";
            }

            //
            if ((Integer.parseInt(strdate) > Integer.parseInt(enddate)) && (msg.equals(""))) {
                msg = "A";
                //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorA.html");
                //return "N";
            }

            //??*****************************************************
            if ((state.equals("I") || (state.equals("U") && !strdate.equals(oldstrdate))) && (msg.equals(""))) {
                cSQL = "SELECT * FROM TCSTCH " + "WHERE TCHCOM=? AND TCHEMP=? AND "
                        + "      ?<=TCHDED AND ?>=TCHDST ";
                prepStmt = connection.prepareStatement(cSQL);
                prepStmt.setString(1, com);
                prepStmt.setString(2, emp);
                //prepStmt.setString(3, tcd);
                prepStmt.setString(3, strdate);
                prepStmt.setString(4, enddate);
                result = prepStmt.executeQuery();
                if (result.next()) {
                    msg = "B";
                    //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorB.html");
                    //return "N";
                }
            }

            //************************************************************* 
            /*
            if ((Integer.parseInt(strdate.substring(0,4)) != Integer.parseInt(enddate.substring(0,4))) && (msg.equals("")))
            {
            msg = "C:??";
            //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorC.html");
            //return "N";
            }*/

            //<=-
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            Calendar c1 = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();

            c1.setTime(sdf.parse(strdate));
            c2.setTime(sdf.parse(enddate));
            cntdays = c2.get(Calendar.DATE) - c1.get(Calendar.DATE) + 1;
            if ((Integer.parseInt(days) > cntdays) && (msg.equals(""))) {
                msg = "E";
                //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorE.html");
                //return "N";
            }

            //??
            if (tcd.equals("B") || tcd.equals("T")) {
                cSQL = " SELECT SUM(CASE WHEN tchtcd = \"B\" THEN 1 ELSE 0 END ) AS sumtkb,"
                        + "        SUM(CASE WHEN tchtcd = \"T\" AND tchtck = \"A\" THEN 1 WHEN tchtcd = \"T\" AND tchtck = \"B\" THEN 2 ELSE 0 END ) AS sumtkt "
                        + " FROM TCSTCH "
                        + " WHERE tchcom = ? AND tchemp = ? AND tchyer = ? AND tchdst <> ? AND tchtcd IN (\"B\",\"T\") AND tchtck NOT IN (\"-\",\"0\") ";
                prepStmt = connection.prepareStatement(cSQL);
                prepStmt.setString(1, com);
                prepStmt.setString(2, emp);
                prepStmt.setString(3, year);
                prepStmt.setString(4, strdate);
                result = prepStmt.executeQuery();
                if (result.next()) {
                    Object obj = result.getObject(1);
                    if (obj != null) {
                        cnttkb = Integer.parseInt(obj.toString());
                    }
                    obj = result.getObject(2);
                    if (obj != null) {
                        cnttkt = Integer.parseInt(obj.toString());
                    }
                }

                if (cnttkb > yeartkb || cnttkt > yeartkt) {
                    tmptck = "0";
                }
            } else if (tcd.equals("M") && (msg.equals(""))) {
                cSQL = " SELECT * FROM TCSTCH "
                        + " WHERE tchcom = ? AND tchemp= ? AND tchtcd = ? AND tchtck NOT IN (\"-\",\"X\") ";
                prepStmt = connection.prepareStatement(cSQL);
                prepStmt.setString(1, com);
                prepStmt.setString(2, emp);
                prepStmt.setString(3, tcd);
                result = prepStmt.executeQuery();
                if (result.next()) {
                    msg = "F";
                    //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorF.html");
                    //return "N";
                }
            } else if (tcd.equals("F")) {
                cSQL = " SELECT COUNT(*) AS times FROM TCSTCH "
                        + " WHERE tchcom = ? AND tchemp= ? AND tchyer = ? AND tchtcd = ? AND tchtck NOT IN (\"-\",\"X\") ";
                prepStmt = connection.prepareStatement(cSQL);
                prepStmt.setString(1, com);
                prepStmt.setString(2, emp);
                prepStmt.setString(3, year);
                prepStmt.setString(4, tcd);
                result = prepStmt.executeQuery();
                if (result.next()) {
                    Object obj = result.getObject(1);
                    if (obj != null && Integer.parseInt(obj.toString()) == 1) {
                        tmptck = "X";
                    }
                }
            }

            //?********************************************************
            if (tcd.equals("C") && (msg.equals(""))) {
                cSQL = " SELECT tchtcd, sum(tchday) AS tchday FROM TCSTCH "
                        + " WHERE tchcom = ? AND tchemp = ? " + "   AND tchyer = ? AND tchdst <> ? "
                        + "   AND tchtcd = \"C\" " + " GROUP BY tchemp ";
                prepStmt = connection.prepareStatement(cSQL);
                prepStmt.setString(1, com);
                prepStmt.setString(2, emp);
                prepStmt.setString(3, year);
                prepStmt.setString(4, oldstrdate);
                result = prepStmt.executeQuery();
                if (!result.wasNull()) {
                    Object obj = result.getObject(2);
                    cntdays = Integer.parseInt(obj.toString()) + Integer.parseInt(days);
                    if (cntdays > 5) {
                        msg = "G";
                        //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorG.html");
                        //return "N";
                    }
                }
            }

            if (msg.equals("")) {
                //<=?
                cSQL = " SELECT * FROM TCSTCH " + " WHERE tchcom = ? AND tchemp = ? "
                        + "   AND tchyer = ? AND tchdst <> ? " + " ORDER BY tchdst DESC ";
                prepStmt = connection.prepareStatement(cSQL);
                prepStmt.setString(1, com);
                prepStmt.setString(2, emp);
                prepStmt.setString(3, year);
                prepStmt.setString(4, oldstrdate);
                result = prepStmt.executeQuery();
                if (result.next()) {
                    Object obj = result.getObject(9);
                    tmplst = Float.parseFloat(obj.toString());
                    if (state.equals("U")) {
                        obj = result.getObject(8);
                        tmplst = tmplst + Integer.parseInt(obj.toString());
                    }
                    tmplst = tmplst - Integer.parseInt(days);
                } else {
                    tmplst = allowdays - Integer.parseInt(days);
                }

                if (tmplst < 0) {
                    msg = "D";
                    //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorD.html");
                    //return "N";
                }
            }
        }

        if (!msg.equals("")) {
            obj1.put("Msg", msg);
            return obj1.toString();
        }

        //
        DateFormat day = new SimpleDateFormat("yyyyMMdd");
        String upddate = day.format(new java.util.Date());
        DateFormat time = new SimpleDateFormat("HHmmss");
        String updtime = time.format(new java.util.Date());

        if (state.equals("I")) {
            cSQL = " INSERT INTO TCSTCH VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            prepStmt = connection.prepareStatement(cSQL);
            prepStmt.setString(1, com);
            prepStmt.setInt(2, Integer.parseInt(year));
            prepStmt.setString(3, emp);
            prepStmt.setString(4, tcd);
            prepStmt.setFloat(5, Float.parseFloat(String.valueOf(allowdays)));
            prepStmt.setInt(6, Integer.parseInt(strdate));
            prepStmt.setInt(7, Integer.parseInt(enddate));
            prepStmt.setFloat(8, Float.parseFloat(days));
            prepStmt.setFloat(9, tmplst);
            prepStmt.setString(10, tmptck);
            prepStmt.setString(11, "");
            prepStmt.setString(12, comment);
            prepStmt.setString(13, "WS_TCS201");
            prepStmt.setString(14, "TEST");
            prepStmt.setInt(15, Integer.parseInt(upddate));
            prepStmt.setInt(16, Integer.parseInt(updtime));

            if (prepStmt.executeUpdate() == 0) {
                obj1.put("Msg", "SI");
                return obj1.toString();
                //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorI.html");
                //return "N";
            }
        } else if (state.equals("U")) {
            cSQL = " UPDATE TCSTCH " + " SET tchdst = ?, " + " tchded = ?, " + " tchday = ?, " + " tchlst = ?, "
                    + " tchtxt = ?, " + " tchpg = ?, " + " tchus = ?, " + " tchdt = ?, " + " tchtm = ? "
                    + " WHERE tchcom = ? AND tchemp = ? AND tchtcd = ? AND tchdst = ? ";
            prepStmt = connection.prepareStatement(cSQL);
            prepStmt.setInt(1, Integer.parseInt(strdate));
            prepStmt.setInt(2, Integer.parseInt(enddate));
            prepStmt.setFloat(3, Float.parseFloat(days));
            prepStmt.setFloat(4, tmplst);
            prepStmt.setString(5, comment);
            prepStmt.setString(6, "WS_TCS201");
            prepStmt.setString(7, "TEST");
            prepStmt.setInt(8, Integer.parseInt(upddate));
            prepStmt.setInt(9, Integer.parseInt(updtime));
            prepStmt.setString(10, com);
            prepStmt.setString(11, emp);
            prepStmt.setString(12, tcd);
            prepStmt.setString(13, oldstrdate);
            String tmptest = prepStmt.toString();

            if (prepStmt.executeUpdate() == 0) {
                obj1.put("Msg", "SU");
                return obj1.toString();
                //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorU.html");
                //return "N";
            }
        } else if (state.equals("D")) {
            cSQL = " DELETE FROM TCSTCH " + " WHERE tchcom = ? AND tchemp = ? AND tchtcd = ? AND tchdst = ? ";
            prepStmt = connection.prepareStatement(cSQL);
            prepStmt.setString(1, com);
            prepStmt.setString(2, emp);
            prepStmt.setString(3, tcd);
            prepStmt.setString(4, oldstrdate);
            if (prepStmt.executeUpdate() == 0) {
                obj1.put("Msg", "SD");
                return obj1.toString();
                //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorD.html");
                //return "N";
            }
        }

        obj1.put("Msg", "SY");
        //servletResponse.sendRedirect("/RestApache/Pages/TCS211_Success.html");
    } catch (SQLException e) {
        prepStmt = null;
        e.printStackTrace();
    } catch (Exception e) {
        prepStmt = null;
        e.printStackTrace();
    }

    return obj1.toString();
    //return "Y";

}

From source file:com.google.mist.plot.MainActivity.java

private void dumpSensorData() throws JSONException { //TODO(cjr): do we want JSONException here?
    File dataDir = getOrCreateSessionDir();
    File target = new File(dataDir, String.format("%s.json", mRecordingType));

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("version", "1.0.0");

    boolean isCalibrated = mPullDetector.getCalibrationStatus();
    jsonObject.put("calibrated", isCalibrated);

    // Write system information
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);// ww  w. java 2s.c om
    JSONObject deviceData = new JSONObject();
    deviceData.put("Build.DEVICE", Build.DEVICE);
    deviceData.put("Build.MODEL", Build.MODEL);
    deviceData.put("Build.PRODUCT", Build.PRODUCT);
    deviceData.put("Build.VERSION.SDK_INT", Build.VERSION.SDK_INT);
    deviceData.put("screenResolution.X", size.x);
    deviceData.put("screenResolution.Y", size.y);
    jsonObject.put("systemInfo", deviceData);

    // Write magnetometer data
    JSONArray magnetData = new JSONArray();
    for (int i = 0; i < mSensorData.size(); i++) {
        JSONArray dataPoint = new JSONArray();
        long time = mSensorTime.get(i);
        dataPoint.put(time);
        dataPoint.put(mSensorAccuracy.get(i));
        float[] data = mSensorData.get(i);
        for (float d : data) {
            dataPoint.put(d);
        }
        magnetData.put(dataPoint);
    }
    jsonObject.put("magnetometer", magnetData);

    // Write onAccuracyChanged data
    JSONArray accuracyChangedData = new JSONArray();
    for (int i = 0; i < mAccuracyData.size(); i++) {
        JSONArray dataPoint = new JSONArray();
        long time = mAccuracyTime.get(i);
        dataPoint.put(time);
        dataPoint.put(mAccuracyData.get(i));
        accuracyChangedData.put(dataPoint);
    }
    jsonObject.put("onAccuracyChangedData", accuracyChangedData);

    // Write rotation data
    if (mRecordRotation) {
        JSONArray rotationData = new JSONArray();
        for (int i = 0; i < mSensorData.size(); i++) {
            JSONArray dataPoint = new JSONArray();
            long time = mRotationTime.get(i);
            dataPoint.put(time);
            float[] data = mRotationData.get(i);
            for (float d : data) {
                dataPoint.put(d);
            }
            rotationData.put(dataPoint);
        }
        jsonObject.put("rotation", rotationData);
    }

    // Write event labels
    JSONArray trueLabels = new JSONArray();
    for (int i = 0; i < mPositivesData.size(); i++) {
        JSONArray dataPoint = new JSONArray();
        long time = mPositivesTime.get(i);
        dataPoint.put(time);
        dataPoint.put(mPositivesData.get(i));
        trueLabels.put(dataPoint);
    }
    jsonObject.put("labels", trueLabels);

    try {
        FileWriter fw = new FileWriter(target, true);
        fw.write(jsonObject.toString());
        fw.flush();
        fw.close();
        mDumpPath = target.toString();
    } catch (IOException e) {
        Log.e(TAG, e.toString());
    }
}

From source file:com.facebook.internal.LikeActionController.java

private static String serializeToJson(LikeActionController controller) {
    JSONObject controllerJson = new JSONObject();
    try {/*from  w  ww.j a v a  2  s . c o m*/
        controllerJson.put(JSON_INT_VERSION_KEY, LIKE_ACTION_CONTROLLER_VERSION);
        controllerJson.put(JSON_STRING_OBJECT_ID_KEY, controller.objectId);
        controllerJson.put(JSON_STRING_LIKE_COUNT_WITH_LIKE_KEY, controller.likeCountStringWithLike);
        controllerJson.put(JSON_STRING_LIKE_COUNT_WITHOUT_LIKE_KEY, controller.likeCountStringWithoutLike);
        controllerJson.put(JSON_STRING_SOCIAL_SENTENCE_WITH_LIKE_KEY, controller.socialSentenceWithLike);
        controllerJson.put(JSON_STRING_SOCIAL_SENTENCE_WITHOUT_LIKE_KEY, controller.socialSentenceWithoutLike);
        controllerJson.put(JSON_BOOL_IS_OBJECT_LIKED_KEY, controller.isObjectLiked);
        controllerJson.put(JSON_STRING_UNLIKE_TOKEN_KEY, controller.unlikeToken);
        if (controller.pendingCallId != null) {
            controllerJson.put(JSON_STRING_PENDING_CALL_ID_KEY, controller.pendingCallId.toString());
        }
        if (controller.pendingCallAnalyticsBundle != null) {
            JSONObject analyticsJSON = BundleJSONConverter.convertToJSON(controller.pendingCallAnalyticsBundle);
            if (analyticsJSON != null) {
                controllerJson.put(JSON_BUNDLE_PENDING_CALL_ANALYTICS_BUNDLE, analyticsJSON);
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, "Unable to serialize controller to JSON", e);
        return null;
    }

    return controllerJson.toString();
}

From source file:com.facebook.internal.LikeActionController.java

private void logAppEventForError(String action, FacebookRequestError error) {
    Bundle logParams = new Bundle();
    if (error != null) {
        JSONObject requestResult = error.getRequestResult();
        if (requestResult != null) {
            logParams.putString(AnalyticsEvents.PARAMETER_LIKE_VIEW_ERROR_JSON, requestResult.toString());
        }//from ww w .j  a  v  a2s  . c  o m
    }
    logAppEventForError(action, logParams);
}