Package org.json

Examples of org.json.JSONTokener


    {
        Reader reader = mapEntityStore.get( EntityReference.parseEntityReference( id ) );
        JSONObject jsonObject;
        try
        {
            jsonObject = new JSONObject( new JSONTokener( reader ) );
        } catch( JSONException e )
        {
            throw (IOException) new IOException().initCause( e );
        }
        reader.close();
View Full Code Here


  /**
   * Example from https://www.dropbox.com/developers/reference/api#account-info in dropbox.account.info.json
   */
  @Test
  public void testJsonParsing() throws Exception {
    JSONObject json = new JSONObject(new JSONTokener(new InputStreamReader(getClass().getResourceAsStream("impl/dropbox.account.info.json"))));
    assertNotNull(json);
    assertEquals(12345678, json.getLong("uid"));
  }
View Full Code Here

     */
    public Widget getMetadata(String url) {
        Widget widget = new Widget();
        JSONObject jsonGadget = null;
        try {
            jsonGadget = (JSONObject) new JSONTokener(gadgetMetadataRepository.getGadgetMetadata(url)).nextValue();
            if ( jsonGadget != null ) {
                String query = jsonGadget.getString("modulePrefs");
                JSONObject jsonModulePrefsObject = (JSONObject) new JSONTokener(query).nextValue();
                if ( jsonModulePrefsObject != null ) {
                    String title = jsonModulePrefsObject.getString("title");
                    String titleUrl = jsonModulePrefsObject.getString("titleUrl");
                    String description =  jsonModulePrefsObject.getString("description");
                    String author = jsonModulePrefsObject.getString("author");
                    String authorEmail = jsonModulePrefsObject.getString("authorEmail");
                    String thumbnailUrl = jsonModulePrefsObject.getString("thumbnail");
                    String screenShot = jsonModulePrefsObject.getString("screenshot");

                    widget.setTitle(title);
                    widget.setTitleUrl(titleUrl);
                    widget.setDescription(description);
                    widget.setAuthor(author);
                    widget.setAuthorEmail(authorEmail);
                    widget.setThumbnailUrl(thumbnailUrl);
                    widget.setScreenshotUrl(screenShot);
                    widget.setUrl(url);
                    widget.setType(getSupportedContext());
                }
            }
        } catch (JSONException e) {
            try {
                String query = jsonGadget.getString("error");
                if (query != null ) {
                    JSONObject jsonModuleErrorObject = (JSONObject) new JSONTokener(query).nextValue();
                    if ( jsonModuleErrorObject != null ) {
                        String errorMessage = jsonModuleErrorObject.getString("message");
                        String errorCode = jsonModuleErrorObject.getString("code");
                        throw new IllegalArgumentException("HTTP error: " + errorCode + ". Message: " + errorMessage);
                    }
View Full Code Here

     */
    public Widget getMetadata(String url) {
        Widget widget = new Widget();
        JSONObject jsonGadget = null;
        try {
            jsonGadget = (JSONObject) new JSONTokener(gadgetMetadataRepository.getGadgetMetadata(url)).nextValue();
            if (jsonGadget != null) {
                String query = jsonGadget.getString("modulePrefs");
                if (query != null) {
                    JSONObject jsonModulePrefsObject = (JSONObject) new JSONTokener(query).nextValue();
                    if (jsonModulePrefsObject != null) {
                        widget.setTitle(parseProperty(jsonModulePrefsObject, "title"));
                        widget.setTitleUrl(parseProperty(jsonModulePrefsObject, "titleUrl"));
                        widget.setDescription(parseProperty(jsonModulePrefsObject, "description"));
                        widget.setAuthor(parseProperty(jsonModulePrefsObject, "author"));
                        widget.setAuthorEmail(parseProperty(jsonModulePrefsObject, "authorEmail"));
                        widget.setThumbnailUrl(parseProperty(jsonModulePrefsObject, "thumbnail"));
                        widget.setScreenshotUrl(parseProperty(jsonModulePrefsObject, "screenshot"));
                        widget.setUrl(url);
                        widget.setType(getSupportedContext());
                    }
                }
            }
        } catch (JSONException e) {
            try {
                String query = jsonGadget.getString("error");
                if (query != null) {
                    JSONObject jsonModuleErrorObject = (JSONObject) new JSONTokener(query).nextValue();
                    if (jsonModuleErrorObject != null) {
                        String errorMessage = jsonModuleErrorObject.getString("message");
                        String errorCode = jsonModuleErrorObject.getString("code");
                        throw new IllegalArgumentException("HTTP error: " + errorCode + ". Message: " + errorMessage);
                    }
View Full Code Here

  }

  @Override
  public QueryResult getQueryResult(final InputStream inputStream, final BindingsFactory bindingsFactory) {
    try {
      final JSONObject object = new JSONObject(new JSONTokener(new InputStreamReader(inputStream)));
      if(object.has("boolean")){
        final boolean b=object.getBoolean("boolean");
        final BooleanResult br = new BooleanResult();
        if(b){
          br.add(bindingsFactory.createInstance());
View Full Code Here

     * @return An object (or tree of objects) representing the data in the JSON
     *         format string.
     * @throws UnmarshallException If unmarshalling fails
     */
    public Object fromJSON(String jsonString) throws UnmarshallException {
        JSONTokener tok = new JSONTokener(jsonString);
        Object json;
        try {
            json = tok.nextValue();
        } catch (JSONException e) {
            throw new UnmarshallException("couldn't parse JSON", e);
        }
        SerializerState state = new SerializerState();
        return this.unmarshall(state, null, json);
View Full Code Here

                IOException ioe = new IOException(
                        "Unable to convert to JSON object");
                ioe.initCause(e);
            }
        } else if (JSONTokener.class.isAssignableFrom(target)) {
            result = new JSONTokener(source.getText());
        } else if (JsonRepresentation.class.isAssignableFrom(target)) {
            result = new JsonRepresentation(source);
        }

        return (T) result;
View Full Code Here

                }
            } 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) {
            try {
                result = this.jsonRepresentation.getText();
            } catch (IOException e) {
View Full Code Here

     * @throws JSONException
     * @deprecated Use {@link #getJsonTokener()} instead.
     */
    @Deprecated
    public JSONTokener toJsonTokener() throws JSONException {
        return new JSONTokener(getJsonText());
    }
View Full Code Here

   */
  public static Token packetToToken(WebSocketPacket aDataPacket) {
    Token lToken = new Token();
    try {
      String lStr = aDataPacket.getString("UTF-8");
      JSONTokener lJSONTokener = new JSONTokener(lStr);
      lToken.setJSONObject(new JSONObject(lJSONTokener));
    } catch (UnsupportedEncodingException ex) {
      // TODO: handle exception
      // log.error(ex.getClass().getSimpleName() + ": " + ex.getMessage());
    } catch (JSONException ex) {
View Full Code Here

TOP

Related Classes of org.json.JSONTokener

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.