Package org.json

Examples of org.json.JSONStringer


    @Test
    @InSequence(1)
    public void testAddMember() throws Exception {
        HttpPost post = new HttpPost(contextPath.toString() + API_PATH);
        post.setHeader("Content-Type", "application/json");
        String newMemberJSON = new JSONStringer().object()
                .key("name").value(NEW_MEMBER_NAME)
                .key("email").value(NEW_MEMBER_EMAIL)
                .key("phoneNumber").value(NEW_MEMBER_PHONE)
                .endObject().toString();
        post.setEntity(new StringEntity(newMemberJSON));
View Full Code Here


{
    JSONWriter json;

    public JSONWriterSerializer()
    {
        this.json = new JSONStringer();
    }
View Full Code Here

   public void marshal(ReadResourceModel model, OutputStream outputStream) 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();

         printWriter.write(new JSONObject(json.toString()).toString(3));
         printWriter.flush();
      }
      catch (JSONException e)
      {
         throw new BindingException("Could not marshal to JSON format", e);
View Full Code Here

                    result = jsonObject.toString(getIndentingSize());
                } else {
                    result = jsonObject.toString();
                }
            } else if (this.jsonValue instanceof JSONStringer) {
                JSONStringer jsonStringer = (JSONStringer) this.jsonValue;
                result = jsonStringer.toString();
            } else if (this.jsonValue instanceof JSONTokener) {
                JSONTokener jsonTokener = (JSONTokener) this.jsonValue;
                result = jsonTokener.toString();
            }
        } else if (this.jsonRepresentation != null) {
View Full Code Here

        Token lBCT = new Token(lNS, "event");
        lBCT.put("name", "init");

        String lData = null;
        try {
          JSONStringer jsonStringer = new JSONStringer();
          // start main object
          jsonStringer.object();
          // iterate through all items (fields) of the token
          Iterator<String> lIterator = sharedObjects.getKeys().iterator();
          while (lIterator.hasNext()) {
            String lKey = lIterator.next();
            Object lVal = sharedObjects.get(lKey);
            if (lVal instanceof Collection) {
              jsonStringer.key(lKey).array();
              for (Object item : (Collection) lVal) {
                jsonStringer.value(item);
              }
              jsonStringer.endArray();
            } else {
              jsonStringer.key(lKey).value(lVal);
            }
          }
          // end main object
          jsonStringer.endObject();
          lData = jsonStringer.toString();
        } catch (JSONException ex) {
          log.error(ex.getClass().getSimpleName() + ": " + ex.getMessage());
        }
        lBCT.put("value", lData);
        getServer().sendToken(aConnector, lBCT);
View Full Code Here

     * @throws JSONException
     *             When JSON string could not be constructed.
     */
    public String getMidiDeviceInfo() throws JSONException
    {
        final JSONStringer js = new JSONStringer();
        js.array();
        for (final Info info : MidiSystem.getMidiDeviceInfo())
        {
            js.object();
            js.key("name").value(info.getName());
            js.key("description").value(info.getDescription());
            js.key("vendor").value(info.getVendor());
            js.key("version").value(info.getVersion());
            js.endObject();
        }
        js.endArray();
        return js.toString();
    }
View Full Code Here

     *             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

     *             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

     */
    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

    @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

TOP

Related Classes of org.json.JSONStringer

Copyright © 2018 www.massapicom. 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.