- JSon Read inner array
- "Manager":
- [
- {
- "name" : "Sample item",
- "icon" : "http://www.test.com/icon.png",
- "link" : "http://www.test.com/sample.zip",
- "summary" : "sample summary here",
- "screenshots": [
- "http://test.com/link2screenshot1.png",
- "http://test.com/link2screenshot2.png"
- ]
- },
- {
- "name" : "Sample item2",
- "icon" : "http://www.test.com/icon2.png",
- "link" : "http://www.test.com/sample2.zip",
- "summary" : "sample summary here2",
- "screenshots": [
- "http://test.com/2/link2screenshot1.png",
- "http://test.com/2/link2screenshot2.png"
- ]
- }
- ]
- public ArrayList<String> JSONInner(int count, String url, String outer, String inner){
- ArrayList<String> linkArrayList = new ArrayList<String>();
- URL u = null;
- StringBuilder FileData = null;
- try {
- u = new URL(url);
- String InputData = null;
- InputStream is = null;
- DataInputStream dis = null;
- FileData = new StringBuilder();
- is = u.openStream();
- dis = new DataInputStream(new BufferedInputStream(is));
- while ((InputData = dis.readLine()) != null) {
- FileData.append(InputData);
- }
- is.close();
- } catch (MalformedURLException e1) {
- e1.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- JSONObject json = null;
- try {
- json = new JSONObject(FileData.toString());
- } catch (JSONException e1) {
- e1.printStackTrace();
- }
- if(FileData.toString() != null) {
- try {
- JSONArray managerArray = json.getJSONArray(outer);
- JSONObject managerObject = managerArray.optJSONObject(count);
- JSONArray linkArray = managerObject.getJSONArray(inner);
- for(int subCount = 0, maxSubCount = linkArray.length(); subCount < maxSubCount; subCount++){
- linkArrayList.add( linkArray.getString( subCount ));
- }
- }catch (JSONException e){
- e.printStackTrace();
- }
- }
- return linkArrayList;
- }
- //Init
- ArrayList<String> linkArrayList = new ArrayList<String>();
- JSONArray managerArray = new JSONArray(yourString);
- //Iterate over the top-level array
- for( int count = 0, max = managerArray.length(); count < max; count++ ) {
- //Get the current JSONObject & the link array
- JSONObject managerObject = managerArray.optJSONObject(count);
- JSONArray linkArray = managerObject.getJSONArray("screenshots");
- //Iterate over the screenshots
- for(
- int subCount = 0, maxSubCount = linkArray.length();
- subcount < maxSubCount;
- subCount++
- ) {
- //Let's store the String
- linkArrayList.add( linkArray.getString( subCount );
- }
- }
- int count = 0; //The 0 should be the index of your item