Examples of JSONTokener


Examples of org.json.JSONTokener

                        public void receive( String item )
                            throws IOException
                        {
                            try
                            {
                                JSONTokener tokener = new JSONTokener( item );
                                JSONObject entity = (JSONObject) tokener.nextValue();
                                String id = entity.getString( JSONKeys.identity.name() );
                                store.put( new EntityReference( id ), item );
                            }
                            catch( JSONException e )
                            {
View Full Code Here

Examples of org.json.JSONTokener

            throw new NoSuchValueException( mixinType.getName(), name() );
        }

        try
        {
            return (T) new JSONDeserializer( model.module() ).deserialize( new JSONTokener( jsonValue ).nextValue(), model.model().valueType() );
        } catch( JSONException e )
        {
            throw new ConstructionException( "Could not create value from JSON", e );
        }
    }
View Full Code Here

Examples of org.json.JSONTokener

            throws EntityStoreException
    {
        try
        {
            Module module = unitOfWork.module();
            JSONObject jsonObject = new JSONObject( new JSONTokener( entityState ) );
            EntityStatus status = EntityStatus.LOADED;

            String version = jsonObject.getString( "version" );
            long modified = jsonObject.getLong( "modified" );
            String identity = jsonObject.getString( "identity" );
View Full Code Here

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

Examples of org.json.JSONTokener

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

Examples of org.json.JSONTokener

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

Examples of org.json.JSONTokener

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

Examples of org.json.JSONTokener

  }

  @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

Examples of org.json.JSONTokener

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

Examples of org.json.JSONTokener

                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
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.