Example usage for org.json JSONObject put

List of usage examples for org.json JSONObject put

Introduction

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

Prototype

public JSONObject put(String key, Object value) throws JSONException 

Source Link

Document

Put a key/value pair in the JSONObject.

Usage

From source file:de.dmxcontrol.programmer.EntityProgrammer.java

public static void Undo(EntityProgrammer programmer) throws JSONException {
    if (programmer == null) {
        return;//from w w w  .  j  ava 2s.  c o m
    }
    JSONObject o = new JSONObject();
    o.put("Type", NetworkID);
    o.put("GUID", programmer.guid);
    o.put("Undo", true);

    ServiceFrontend.get().sendMessage(o.toString().getBytes());
    o = null;
    if (o == null) {
        ;
    }
    return;
}

From source file:de.dmxcontrol.programmer.EntityProgrammer.java

public static void ClearSelection(EntityProgrammer programmer) throws JSONException {
    if (programmer == null) {
        return;/*from  w w w  . j a va  2s  .co m*/
    }
    JSONObject o = new JSONObject();
    o.put("Type", NetworkID);
    o.put("GUID", programmer.guid);
    o.put("ClearSelection", true);

    ServiceFrontend.get().sendMessage(o.toString().getBytes());
    o = null;
    if (o == null) {
        ;
    }
    return;
}

From source file:JSON.GenererJSONSave.java

/**
 * Methode pour sauvegarder le plateau d'un jeu
 * @param p /*from  w ww.j a  va2  s  . com*/
 */
public void Save(Plateau p) {
    ArrayList<Sauvegarde> Liste = new ArrayList();
    int k = 0;
    for (int i = 0; i < p.getAbsci(); i++) {
        for (int j = 0; j < p.getOrdonne(); j++) {
            if (p.grille[i][j] != null)
                Liste.add(new Sauvegarde(i, j, p.grille[i][j].nom));

        }
    }
    JSONObject objet = new JSONObject();
    JSONArray jsArray = new JSONArray(Liste);
    objet.put("coordonne", jsArray);
    // Cration du fichier de sortie
    FileWriter fs = null;
    try {
        fs = new FileWriter("C:\\Users\\Alphonse\\Desktop\\output2.txt");
    } catch (IOException e) {
        System.err.println("Erreur lors de l'ouverture du fichier ");
        System.err.println(e);
        System.exit(-1);
    }

    // Sauvegarde dans le fichier
    try {
        objet.write(fs);
        fs.flush();
    } catch (IOException e) {
        System.err.println("Erreur lors de l'criture dans le fichier : " + e);
        System.exit(-1);
    }
}

From source file:com.acrutiapps.browser.tasks.HistoryBookmarksExportTask.java

private String writeAsJSON(Cursor... params) {
    try {//from w  w  w . ja v a 2 s.  c  o m
        String fileName = mContext.getString(R.string.ApplicationName) + "-" + getNowForFileName() + ".json";

        File file = new File(Environment.getExternalStorageDirectory(), fileName);
        FileWriter writer = new FileWriter(file);

        FoldersJSONArray foldersArray = new FoldersJSONArray();
        BookmarksJSONArray bookmarksArray = new BookmarksJSONArray();
        HistoryJSONArray historyArray = new HistoryJSONArray();

        Cursor c = params[0];
        if (c.moveToFirst()) {

            int current = 0;
            int total = c.getCount();

            int idIndex = c.getColumnIndex(BookmarksProvider.Columns._ID);
            int titleIndex = c.getColumnIndex(BookmarksProvider.Columns.TITLE);
            int urlIndex = c.getColumnIndex(BookmarksProvider.Columns.URL);
            int creationDateIndex = c.getColumnIndex(BookmarksProvider.Columns.CREATION_DATE);
            int visitedDateIndex = c.getColumnIndex(BookmarksProvider.Columns.VISITED_DATE);
            int visitsIndex = c.getColumnIndex(BookmarksProvider.Columns.VISITS);
            int bookmarkIndex = c.getColumnIndex(BookmarksProvider.Columns.BOOKMARK);
            int folderIndex = c.getColumnIndex(BookmarksProvider.Columns.IS_FOLDER);
            int parentfolderIdIndex = c.getColumnIndex(BookmarksProvider.Columns.PARENT_FOLDER_ID);

            while (!c.isAfterLast()) {

                publishProgress(1, current, total);

                boolean isFolder = c.getInt(folderIndex) > 0 ? true : false;

                if (isFolder) {
                    String title = c.getString(titleIndex);
                    title = title != null ? URLEncoder.encode(title, "UTF-8") : "";

                    foldersArray.add(title, c.getLong(idIndex), c.getLong(parentfolderIdIndex));

                } else {
                    boolean isBookmark = c.getInt(bookmarkIndex) > 0 ? true : false;

                    String title = c.getString(titleIndex);
                    title = title != null ? URLEncoder.encode(title, "UTF-8") : "";

                    String url = c.getString(urlIndex);
                    url = url != null ? URLEncoder.encode(url, "UTF-8") : "";

                    if (isBookmark) {
                        bookmarksArray.add(c.getLong(parentfolderIdIndex), title, url,
                                c.getLong(creationDateIndex), c.getLong(visitedDateIndex),
                                c.getInt(visitsIndex));
                    } else {
                        historyArray.add(title, url, c.getLong(visitedDateIndex), c.getInt(visitsIndex));
                    }
                }

                current++;
                c.moveToNext();
            }
        }

        JSONObject output = new JSONObject();
        output.put("folders", foldersArray);
        output.put("bookmarks", bookmarksArray);
        output.put("history", historyArray);

        writer.write(output.toString(1));

        writer.flush();
        writer.close();

    } catch (JSONException e) {
        e.printStackTrace();
        return e.getMessage();
    } catch (IOException e) {
        e.printStackTrace();
        return e.getMessage();
    }

    return null;
}

From source file:org.exoplatform.addons.codefest.team_c.controller.KittenSaverController.java

@Resource
@Ajax/*from   w  w w  .  j  a v  a  2 s.c o m*/
@MimeType.JSON
public Response changeDate(String participants, int date, int month, int year) throws JSONException {
    JSONObject json = new JSONObject();
    json.put("url", KittenSaverController_.addView(participants, date, month, year));
    return Response.ok(json.toString()).withCharset(Tools.UTF_8);
}

From source file:org.exoplatform.addons.codefest.team_c.controller.KittenSaverController.java

@Resource
@Ajax/*w w  w . j a v  a  2s . c om*/
@MimeType.JSON
public Response addOption(Long start, Long end, SecurityContext securityContext) throws JSONException {
    User user = kittenSaverService.getUserByUsername(securityContext.getRemoteUser());
    TimeZone timezone = TimeZone.getTimeZone(user.getTimezone());
    Calendar sCal = Calendar.getInstance(timezone);
    sCal.setTimeInMillis(start);
    Calendar eCal = Calendar.getInstance(timezone);
    eCal.setTimeInMillis(end);

    JSONObject json = new JSONObject();
    json.put("start", format(sCal));
    json.put("end", format(eCal));

    return Response.ok(json.toString()).withCharset(Tools.UTF_8);
}

From source file:org.exoplatform.addons.codefest.team_c.controller.KittenSaverController.java

@Resource
@Ajax/* w w  w  . j  a  va 2 s .c  o m*/
@MimeType.JSON
public Response addMeeting(String title, String description, String participants, String options,
        SecurityContext securityContext) throws JSONException {
    List<String> pars = new LinkedList<String>(Arrays.asList(participants.split(",")));
    List<Long> opts = new LinkedList<Long>();
    for (String opt : options.split(",")) {
        String[] time = opt.split("/");
        Date startDate = new Date();
        startDate.setTime(Long.parseLong(time[0]));
        Date endDate = new Date();
        endDate.setTime(Long.parseLong(time[1]));
        Option o = new Option(new LinkedList<Long>(), startDate, endDate);
        kittenSaverService.createOption(o);
        opts.add(o.getId());
    }

    User user = kittenSaverService.getUserByUsername(securityContext.getRemoteUser());
    Meeting meeting = new Meeting(title, description, user, Meeting.STATUS_OPENED, pars, opts, null);
    kittenSaverService.createMeeting(meeting);

    JSONObject json = new JSONObject();
    json.put("url", KittenSaverController_.index());
    return Response.ok(json.toString()).withCharset(Tools.UTF_8);
}

From source file:PlayerInfo.Player.java

public JSONObject putBalance(double d) {
    JSONObject putCurrentBalance = new JSONObject();
    try {/*from   ww  w  . j av a 2 s .  c o m*/
        putCurrentBalance.put("balance", d);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(putCurrentBalance);
    return putCurrentBalance;
}

From source file:feedme.controller.UpdateCategoryServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from   w  ww.ja  v  a2  s .c om
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);

    String city = request.getParameter("city");
    HashMap<String, Integer> cat = new DbHPOnLoad().getCategoriesByCity(city);
    try {

        JSONObject catObj = new JSONObject();
        catObj.put("categorys", new JSONArray());
        JSONArray cate = catObj.getJSONArray("categorys");
        for (Map.Entry<String, Integer> entry : cat.entrySet()) {
            cate.put(new JSONObject().put("cat_id", entry.getValue()).put("cat_name", entry.getKey()));
        }
        response.setContentType("application/json");
        PrintWriter writer = response.getWriter();
        writer.print(catObj);
        response.getWriter().flush();

    } catch (JSONException ex) {
        Logger.getLogger(OrderCompleteServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.loklak.server.Accounting.java

public synchronized Accounting addRequest(String path, String query) {
    if (!this.has("requests"))
        this.put("requests", new JSONObject());
    JSONObject requests = this.getJSONObject("requests");
    if (!requests.has(path))
        requests.put(path, new TreeMap<String, String>());
    JSONObject events = requests.getJSONObject(path);
    events.put(Long.toString(System.currentTimeMillis() + ((uc++) % 1000)), query); // the counter is used to distinguish very fast concurrent requests
    return this;
}