Reputation: 17
I am using Quick Json to parse a json String in the format to retrieve the title of all songs
{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"}, "songs": [{"artist_id": "ARJHCSL123E29C21E8", "id": "SOENBWC13E58ECFBDD", "artist_name": "Bruno Mars", "title": "Grenade (En Vivo @ SXM)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOHQYKB130516E0C3B", "artist_name": "Bruno Mars", "title": "Bruno Mars - Just The Way You Are (Lee Wright Remix)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOFGCTK13DBAFD643B", "artist_name": "Bruno Mars", "title": "Young, Wild & Free (Originally Performed By Snoop Dogg, Wiz Khalifa) [Karaoke Version]"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOJGNLU12C0DD05554", "artist_name": "Bruno Mars", "title": "GRENADE (Clean)/(CONTENT!)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOQJPOT13E58EA39D4", "artist_name": "Bruno Mars", "title": "Just The Way You Are (En Vivo @ SXM)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOBXSGM1468D0E25AD", "artist_name": "Bruno Mars", "title": "Locked Out Of Heaven - Manhattan's XOYO Mix"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOIVCUQ13D3EE80CED", "artist_name": "Bruno Mars", "title": "Nothing On You"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOKLXMU12AF72A8FE6", "artist_name": "Bruno Mars", "title": "Count On Me (EP Version)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOXHAGE1340BBA40EC", "artist_name": "Bruno Mars", "title": "Just The Way You Are (Carl Louis & Martin Danielle Classic Mix)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOMYEUN141E947704E", "artist_name": "Bruno Mars", "title": "Grenade (Michael Meds Mix)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOTSIBX136C2EE52F3", "artist_name": "Bruno Mars", "title": "DJ T Finguz Cadillac MIX"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOVSSEW1312FDFC23C", "artist_name": "Bruno Mars", "title": "The Lazy Song (Official Remix)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOTUEIS135A61E6B89", "artist_name": "Bruno Mars", "title": "Just the Way You Are (Ultrafunk Dance Remix)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SOAFTQW13EB2D8A84F", "artist_name": "Bruno Mars", "title": "This Is My Love (Victor Magan Remix)"}, {"artist_id": "ARJHCSL123E29C21E8", "id": "SORCBZR14491454F1C", "artist_name": "Bruno Mars", "title": "Locked Out of Heaven (Sultan and Ned Shepard Remix) [Radio Edit]"}]}}
The API that I am using is Songs API. I am trying to parse the hashmap but I am getting null. If anyone can tell me how to parse the hashmap to get the title
JsonParserFactory factory=JsonParserFactory.getInstance();
JSONParser parser = factory.newJsonParser();
Map jsonData=parser.parseJson(StringJson);
String f = (String)jsonData.get("response");
Upvotes: 0
Views: 87
Reputation: 3682
the following gives you list of all titles:
List f = (List) (((Map) jsonData.get("response")).get("songs"));
Iterator iter = f.iterator();
while(iter.hasNext()){
System.out.println(((Map) iter.next()).get("title"));
}
Upvotes: 1