Hi I'm working on a dynamic android application and i have the following json. Reading each line is fine i've figured out how to do this in java (keep in mind i just started working with json yesterday) how can i read the inner array of say sample item2 to an ArrayList in java i need some kind of loop to add to a string array the screen shot links. Thank you for any help with my problem.
"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"
]
}
]
===EDIT===
Alright here is the final solution the following method will read a json from a url and pull what i want thanks to ninetwozero
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;
}