Examples of JSONStringer


Examples of org.json.JSONStringer

     *             When JSON data could not be constructed.
     */
    public String getReceivers(final int deviceHandle) throws JSONException
    {
        final MidiDevice device = resolveDeviceHandle(deviceHandle);
        final JSONStringer json = new JSONStringer();
        json.array();
        for (final Receiver receiver : device.getReceivers())
        {
            json.value(System.identityHashCode(receiver));
        }
        json.endArray();
        return json.toString();
    }
View Full Code Here

Examples of org.json.JSONStringer

     *             When JSON data could not be constructed.
     */
    public String getTransmitters(final int deviceHandle) throws JSONException
    {
        final MidiDevice device = resolveDeviceHandle(deviceHandle);
        final JSONStringer json = new JSONStringer();
        json.array();
        for (final Transmitter transmitter : device.getTransmitters())
        {
            json.value(System.identityHashCode(transmitter));
        }
        json.endArray();
        return json.toString();
    }
View Full Code Here

Examples of org.json.JSONStringer

     */
    public String getMidiDeviceInfo(final int deviceHandle)
        throws JSONException
    {
        final MidiDevice device = resolveDeviceHandle(deviceHandle);
        final JSONStringer json = new JSONStringer();
        deviceInfo(json, device.getDeviceInfo());
        return json.toString();
    }
View Full Code Here

Examples of org.json.JSONStringer

    @Override
    public void send(final MidiMessage message, final long timeStamp)
    {
        try
        {
            final JSONStringer json = new JSONStringer();
            json.object();
            json.key("status").value(message.getStatus());
            json.key("message");
            json.array();
            final byte[] data = message.getMessage();
            final int max = Math.min(data.length, message.getLength());
            for (int i = 0; i < max; i++)
                json.value(data[i] & 0xff);
            json.endArray();
            if (message instanceof ShortMessage)
                processShortMessage((ShortMessage) message, json);
            else if (message instanceof MetaMessage)
                processMetaMessage((MetaMessage) message, json);
            else if (message instanceof SysexMessage)
                processSysexMessage((SysexMessage) message, json);
            json.endObject();
            this.applet.execJSMethod("messageReceived",
                System.identityHashCode(this),
                json.toString(), timeStamp);
        }
        catch (final JSONException e)
        {
            throw new RuntimeException(e.toString(), e);
        }
View Full Code Here

Examples of org.json.JSONStringer

   public void marshal(ReadResourceModel model, OutputStream outputStream, boolean pretty) throws BindingException
   {
      PrintWriter printWriter = new PrintWriter(outputStream);
      try
      {
         JSONStringer json = new JSONStringer();
         json.object().key("description").value(model.getDescription());
         json.key("children").array();
         for (String child : model.getChildren())
         {
            json.object().key("name").value(child);
            NamedDescription nd = model.getChildDescription(child);
            if (nd != null)
            {
               json.key("description").value(nd.getDescription());
            }
            json.endObject();
         }
         json.endArray().key("operations").array();
         for (NamedDescription nd : model.getOperations())
         {
            json.object().key("operation-name").value(nd.getName()).key("operation-description").value(nd.getDescription()).endObject();
         }
         json.endArray().endObject();

         JSONObject output = new JSONObject(json.toString());
         if (pretty)
         {
            printWriter.write(output.toString(3));
         }
         else
View Full Code Here

Examples of org.json.JSONStringer

            } catch (Exception e) {
              e.printStackTrace();
            }
        }
       
          JSONStringer stringer = new JSONStringer();
          MfGeoJSONWriter builder = new MfGeoJSONWriter(stringer);
          builder.encodeFeatureCollection(new MfFeatureCollection(outputFeatureCollection));
         
          servletIOManager.tryToWriteBackToClient(stringer.toString());
     
    } catch(Throwable t) {
      t.printStackTrace();
    } finally {
      logger.debug("OUT");
View Full Code Here

Examples of org.json.JSONStringer

    }
    return null;
  }

  public static String getSampleJsonString(int numRows) {
    JSONStringer x = new JSONStringer();
    Random rand = new Random(0);
    try {
      JSONWriter top = x.array();
      for (int i = 1; i <= numRows; i++) {
        JSONWriter o = top.object();
        o.key("a").value("a" + i);

        o.key("b").value("b" + i);

        JSONWriter c = o.key("c").array();
        for (int ci = 1; ci <= 10; ci++) {
          JSONWriter co = c.object();
          co.key("c.1").value("c.1_" + ci);
          if (rand.nextBoolean()) {
            co.key("c.2").value("c.2_" + ci);
          }

          if (rand.nextBoolean()) {
            JSONWriter c3a = co.key("c.3").array();

            for (int c3i = 1; c3i < rand.nextInt(10) + 1; c3i++) {
              JSONWriter c3o = c3a.object();
              if (rand.nextBoolean()) {
                co.key("c.3.1").value(
                    "c.3.1_" + c3i + "+" + ci + "+" + i);
              }
              if (rand.nextBoolean()) {
                co.key("c.3.2").value("c.3.2_" + c3i);
              }
              if (rand.nextBoolean()) {
                co.key("c.3.3").value("c.3.3_" + c3i);
              }
              if (rand.nextBoolean()) {
                JSONWriter c34o = co.key("c.3.4").object();
                c34o.key("c.3.4.1").value("c.3.4.1_X");
                c34o.key("c.3.4.2").value("c.3.4.1_Y");
                c34o.endObject();
              }
              c3o.endObject();
            }

            c3a.endArray();
          }

          co.endObject();
        }
        c.endArray();

        // List of primitive values.
        JSONWriter d = o.key("d").array();
        for (int di = 1; di < rand.nextInt(10) + 1; di++) {
          d.value("d" + di);
        }
        d.endArray();

        JSONWriter e = o.key("e").array();
        for (int ei = 1; ei < rand.nextInt(10) + 1; ei++) {
          if (rand.nextBoolean()) {
            e.value("e" + ei + "+" + i);
          } else {
            e.object().key("e.1").value("e.1_" + ei).key("e.2")
                .value("e.2_" + ei).endObject();
          }
        }
        e.endArray();

        o.endObject();
      }
      top.endArray();
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    return x.toString();
  }
View Full Code Here

Examples of org.json.JSONStringer

    return x.toString();
  }

  public static String getJsonForUnitTest1() {
    JSONStringer x = new JSONStringer();
    Random rand = new Random(0);
    try {
      JSONWriter top = x.array();
      for (int i = 1; i <= 2; i++) {
        JSONWriter o = top.object();
        o.key("a").value("a" + i);

        o.key("b").value("b" + i);

        JSONWriter c = o.key("c").array();
        for (int ci = 1; ci <= 10; ci++) {
          JSONWriter co = c.object();
          co.key("c.1").value("c.1_" + ci);
          if (rand.nextBoolean()) {
            co.key("c.2").value("c.2_" + ci);
          }

          if (rand.nextBoolean()) {
            //
          }

          co.endObject();
        }
        c.endArray();

        // List of primitive values.
        JSONWriter d = o.key("d").array();
        for (int di = 1; di < rand.nextInt(10) + 1; di++) {
          d.value("d" + di);
        }
        d.endArray();

        JSONWriter e = o.key("e").array();
        for (int ei = 1; ei < rand.nextInt(10) + 1; ei++) {
          if (rand.nextBoolean()) {
            e.value("e" + ei + "+" + i);
          } else {
            e.object().key("e.1").value("e.1_" + ei).key("e.2")
                .value("e.2_" + ei).endObject();
          }
        }
        e.endArray();

        o.endObject();
      }
      top.endArray();
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    return x.toString();
  }
View Full Code Here

Examples of org.json.JSONStringer

    return x.toString();
  }

  public static String getJsonForUnitTest4() {
    JSONStringer x = new JSONStringer();
    Random rand = new Random(0);
    try {
      JSONWriter top = x.array();
      for (int i = 1; i <= 1; i++) {
        JSONWriter o = top.object();

        JSONWriter c = o.key("c").array();
        for (int ci = 1; ci <= 3; ci++) {
          JSONWriter co = c.object();
          if (rand.nextBoolean()) {
            co.key("c.2").value("c.2_" + ci);
          }

          if (rand.nextBoolean()) {
            JSONWriter c3a = co.key("c.3").array();

            for (int c3i = 1; c3i < 3; c3i++) {
              JSONWriter c3o = c3a.object();
              if (rand.nextBoolean()) {
                co.key("c.3.1").value(
                    "c.3.1_" + c3i + "+" + ci + "+" + i);
              }
              if (rand.nextBoolean()) {
                co.key("c.3.3").value("c.3.3_" + c3i);
              }
              if (rand.nextBoolean()) {
                JSONWriter c34o = co.key("c.3.4").object();
                c34o.key("c.3.4.2").value("c.3.4.1_Y");
                c34o.endObject();
              }
              c3o.endObject();
            }

            c3a.endArray();
          }

          co.endObject();
        }
        c.endArray();

        o.endObject();
      }
      top.endArray();
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    return x.toString();
  }
View Full Code Here

Examples of org.json.JSONStringer

    return x.toString();
  }

  public static String getJsonForUnitTest5() {
    JSONStringer x = new JSONStringer();
    Random rand = new Random(0);
    try {
      JSONWriter top = x.array();
      for (int i = 1; i <= 1; i++) {
        JSONWriter o = top.object();

        JSONWriter c = o.key("c").array();
        for (int ci = 1; ci <= 4; ci++) {
          JSONWriter co = c.object();
          co.key("c.1").value("c.1_" + ci);
          if (rand.nextBoolean()) {
            // Need the call to rand to make the test come out
            // right.
          }

          if (rand.nextBoolean()) {
            JSONWriter c3a = co.key("c.3").array();

            for (int c3i = 1; c3i < rand.nextInt(10) + 1; c3i++) {
              JSONWriter c3o = c3a.object();
              if (rand.nextBoolean()) {
                co.key("c.3.1").value(
                    "c.3.1_" + c3i + "+" + ci + "+" + i);
              }
              if (rand.nextBoolean()) {
                co.key("c.3.2").value("c.3.2_" + c3i);
              }
              if (rand.nextBoolean()) {
                co.key("c.3.3").value("c.3.3_" + c3i);
              }
              if (rand.nextBoolean()) {
                JSONWriter c34o = co.key("c.3.4").object();
                c34o.key("c.3.4.1").value("c.3.4.1_X");
                c34o.key("c.3.4.2").value("c.3.4.1_Y");
                c34o.endObject();
              }
              c3o.endObject();
            }

            c3a.endArray();
          }

          co.endObject();
        }
        c.endArray();

        JSONWriter e = o.key("e").array();
        for (int ei = 1; ei < 6; ei++) {
          if (rand.nextBoolean()) {
            e.value("e" + ei + "+" + i);
          } else {
            e.object().key("e.1").value("e.1_" + ei).endObject();
          }
        }
        e.endArray();

        o.endObject();
      }
      top.endArray();
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    return x.toString();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.