EZMusicBoxSDK/src/main/java/com/wms/ezmusicbox/sdk/util/MusicUtil.java
// Load music list from assets/music_list.json
Load music list from assets/music_list.json
Load music list from assets / music_list . json
public static List<Music> loadMustList(Context context) {
		List<Music> musicList = new ArrayList<>();
		BufferedReader br = null;
		try {
			StringBuffer sb = new StringBuffer();
			br = new BufferedReader(new InputStreamReader(context.getAssets().open("music_list.json")));
			String temp;
			while ((temp = br.readLine()) != null) {
				sb.append(temp);
			}
			JSONObject jsonObjMain = new JSONObject(sb.toString());
			JSONArray jsonArray = jsonObjMain.getJSONArray("list");
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject jsonObj = jsonArray.getJSONObject(i);
				String author = jsonObj.getString("author");
				String name = jsonObj.getString("name");
				String url = jsonObj.getString("url");
				int size = jsonObj.getInt("size");
				int duration = jsonObj.getInt("duration");
				Music music = new Music(author, name, url, size, duration);
				musicList.add(music);
			}
		}
		catch (JSONException | IOException e) {
		}
		finally {
			try {
				br.close();
			}
			catch (IOException e) {
			}
		}
		return musicList;
	}
public static List < Music > loadMustList ( Context context ) { List < Music > musicList = new ArrayList < > ( ) ; BufferedReader br = null ; try { StringBuffer sb = new StringBuffer ( ) ; br = new BufferedReader ( new InputStreamReader ( context . getAssets ( ) . open ( "music_list.json" ) ) ) ; String temp ; while ( ( temp = br . readLine ( ) ) != null ) { sb . append ( temp ) ; } JSONObject jsonObjMain = new JSONObject ( sb . toString ( ) ) ; JSONArray jsonArray = jsonObjMain . getJSONArray ( "list" ) ; for ( int i = 0 ; i < jsonArray . length ( ) ; i ++ ) { JSONObject jsonObj = jsonArray . getJSONObject ( i ) ; String author = jsonObj . getString ( "author" ) ; String name = jsonObj . getString ( "name" ) ; String url = jsonObj . getString ( "url" ) ; int size = jsonObj . getInt ( "size" ) ; int duration = jsonObj . getInt ( "duration" ) ; Music music = new Music ( author , name , url , size , duration ) ; musicList . add ( music ) ; } } catch ( JSONException | IOException e ) { } finally { try { br . close ( ) ; } catch ( IOException e ) { } } return musicList ; }
Load music list from assets/music_list.json
Load music list from assets / music_list . json
// Reading json file from assets folder // Creating JSONObject from String // Creating JSONArray from JSONObject // JSONArray has four JSONObject // Creating JSONObject from JSONArray // Getting data from individual JSONObject // Close buffer reader