Package org.codehaus.jettison.json

Examples of org.codehaus.jettison.json.JSONArray


    //public JSONObject getUser(@PathParam("userid") String userid) throws JSONException, Exception {
       public JSONArray getUsers() throws JSONException, Exception {
      logger.finer(" get USERs is here !");
      mf = (ModelFacade)getServletContext().getAttribute(WebConstants.MF_KEY);
      List<Person> allUsers = mf.getAllPersons();
       JSONArray uriArray = new JSONArray();
        for (Person userEntity : allUsers) {
            UriBuilder ub = uriInfo.getAbsolutePathBuilder();
            URI userUri = ub.
                    path(userEntity.getUserName()).
                    build();
            uriArray.put(userUri.toASCIIString());
        }
        return uriArray;

  }
View Full Code Here


    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject apps = json.getJSONObject("apps");
    assertEquals("incorrect number of elements", 1, apps.length());
    JSONArray array = apps.getJSONArray("app");
    assertEquals("incorrect number of elements", 5, array.length());
  }
View Full Code Here

    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject appAttempts = json.getJSONObject("appAttempts");
    assertEquals("incorrect number of elements", 1, appAttempts.length());
    JSONArray array = appAttempts.getJSONArray("appAttempt");
    assertEquals("incorrect number of elements", 5, array.length());
  }
View Full Code Here

    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject containers = json.getJSONObject("containers");
    assertEquals("incorrect number of elements", 1, containers.length());
    JSONArray array = containers.getJSONArray("container");
    assertEquals("incorrect number of elements", 5, array.length());
  }
View Full Code Here

        if (entity != null) {
            try {
                JSONObject object = Client.create().resource("http://ws.spotify.com/search/1/album.json?q=album:" + URLEncoder.encode(entity.getName(), "utf8")).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                result.setCount(object.getJSONObject("info").getInt("num_results"));
                List<ResultItem<SpotifyAlbum>> albums = new ArrayList<ResultItem<SpotifyAlbum>>();
                JSONArray array = object.getJSONArray("albums");
                for (int i = 0; i < array.length(); i++) {
                    ResultItem<SpotifyAlbum> item = createFromJSON(array.getJSONObject(i));
                    if (item != null) {
                        if((firstItem==null || result.getCount()>=firstItem) && (maxItems==null || maxItems>albums.size())) {
                            albums.add(item);
                        }
                        result.setCount(result.getCount()+1);
                    }
                }
                result.setItems(albums);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else if (currentId.startsWith(SpotifyArtist.class.getSimpleName() + ":")) {
            try {
                JSONObject object = Client.create().resource("http://ws.spotify.com/lookup/1/.json?uri=" + currentId.substring(14) + "&extras=album").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<SpotifyAlbum>> albums = new ArrayList<ResultItem<SpotifyAlbum>>();
                JSONArray array = object.getJSONObject("artist").getJSONArray("albums");
                for (int i = 0; i < array.length(); i++) {
                    ResultItem<SpotifyAlbum> item = createFromJSON(array.getJSONObject(i).getJSONObject("album"));
                    if (item != null) {
                        if((firstItem==null || result.getCount()>=firstItem) && (maxItems==null || maxItems>albums.size())) {
                            albums.add(item);
                        }
                        result.setCount(result.getCount()+1);
View Full Code Here

        List<OnlinePlayableElement> result = new ArrayList<OnlinePlayableElement>();
        for (String criteria : criteriaList) {
            if (criteria.startsWith(SpotifyAlbum.class.getSimpleName())) {
                JSONObject object = Client.create().resource("http://ws.spotify.com/lookup/1/.json?uri=" + criteria.substring(13) + "&extras=track").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                try {
                    JSONArray array = object.getJSONObject("album").getJSONArray("tracks");
                    for (int i = 0; i < array.length(); i++) {
                        result.add(new OnlinePlayableElement(array.getJSONObject(i).getString("href")));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
View Full Code Here

            globalIdentity.setEntityId(release.getId());
            globalIdentity.setLastUpdated(currentTime);
            globalIdentity.setLastUpdatedBy(SPOTIFY_SOURCE);
            globalIdentityRepository.create(globalIdentity);

            JSONArray array = jsonAlbum.getJSONArray("tracks");
            for (int i = 0; i < array.length(); i++) {
                JSONObject jsonTrack = array.getJSONObject(i);

                WorkEntity work = new WorkEntity();
                work.setName(jsonTrack.getString("name"));
                work.setLastUpdated(currentTime);
                work.setLastUpdatedBy(SPOTIFY_SOURCE);
                workRepository.create(work);

                RecordingEntity recording = new RecordingEntity();
                recording.setLastUpdated(currentTime);
                recording.setLastUpdatedBy(SPOTIFY_SOURCE);
                recordingRepository.create(recording);
                recording.getWorks().add(work);

                TrackEntity track = new TrackEntity();
                if (jsonTrack.has("track-number")) {
                    track.setNumber(jsonTrack.getInt("track-number"));
                }
                track.setRecording(recording);
                release.addTrack(track);
                track.setLastUpdated(currentTime);
                track.setLastUpdatedBy(SPOTIFY_SOURCE);
                trackRepository.create(track);

                PlayableElementEntity playableElement = new PlayableElementEntity();
                playableElement.setSmdID(jsonTrack.getString("href"));
                playableElement.setUri(jsonTrack.getString("href"));
                playableElement.setFormat(SPOTIFY_SOURCE);
                playableElement.setLastUpdated(currentTime);
                playableElement.setLastUpdatedBy(SPOTIFY_SOURCE);
                playableElementRepository.create(playableElement);
                track.getPlayableElements().add(playableElement);

                JSONArray jsonArtists = jsonTrack.optJSONArray("artists");
                if (jsonArtists != null && jsonArtists.length() > 0) {
                    for (int j = 0; j < jsonArtists.length(); j++) {
                        JSONObject jsonArtist = jsonArtists.getJSONObject(j);
                        String name = jsonArtist.getString("name");
                        Collection<ArtistEntity> artists = artistRepository.findByName(name);
                        if (artists.size() == 0) {
                            artists = new ArrayList<ArtistEntity>();
                            ArtistEntity artist = new ArtistEntity();
View Full Code Here

        if (entity != null) {
            try {
                JSONObject object = Client.create().resource(getLastFmUrl("album.search&album=" + urlEncode(entity.getName()))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMAlbum>> albums = new ArrayList<ResultItem<LastFMAlbum>>();
                JSONArray array = object.getJSONObject("results").getJSONObject("albummatches").getJSONArray("album");
                result.setCount(array.length());
                for (int i = 0; i < array.length(); i++) {
                    if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>albums.size())) {
                        albums.add(createFromJSON(array.getJSONObject(i)));
                    }
                }
                result.setCount(albums.size());
                result.setItems(albums);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else if (currentId.startsWith(LastFMArtist.class.getSimpleName() + ":")) {
            try {
                String artistId = currentId.substring(13);
                JSONObject object = Client.create().resource(getLastFmUrl("artist.gettopalbums" + createQueryFromId(artistId))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMAlbum>> albums = new ArrayList<ResultItem<LastFMAlbum>>();
                if (object.getJSONObject("topalbums").has("album")) {
                    JSONArray array = object.getJSONObject("topalbums").getJSONArray("album");
                    result.setCount(array.length());
                    for (int i = 0; i < array.length(); i++) {
                        if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>albums.size())) {
                            albums.add(createFromJSON(array.getJSONObject(i)));
                        }
                    }
                }
                result.setItems(albums);
            } catch (JSONException e) {
View Full Code Here

                    artist = json.getString("artist");
                }
                id = "artist:" + urlEncode(artist) + ":album:" + urlEncode(json.getString("name"));
            }
            String image = null;
            JSONArray images = json.optJSONArray("image");
            if(images!=null && images.length()>0) {
                image = images.getJSONObject(images.length()-1).getString("#text");
                if(image.length()==0) {
                    image = null;
                }
            }
            String name = json.getString("name");
View Full Code Here

        if (entity != null) {
            try {
                JSONObject object = Client.create().resource(getLastFmUrl("artist.search&artist=" + urlEncode(entity.getName()))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMArtist>> artists = new ArrayList<ResultItem<LastFMArtist>>();
                JSONArray array = object.getJSONObject("results").getJSONObject("artistmatches").getJSONArray("artist");
                result.setCount(array.length());
                for (int i = 0; i < array.length(); i++) {
                    if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>artists.size())) {
                        artists.add(createFromJSON(array.getJSONObject(i)));
                    }
                }
                result.setItems(artists);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.codehaus.jettison.json.JSONArray

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.