I'm trying to create a image gallery in my app. I've got the images in JSON and I'd like to create a String Array from the JSON Objects in an AsyncTask so I can pop the String Array into Universal Image Loader. I think I've got the AsyncTask correctly getting the strings, but I'm stumped as to how to put the strings in an Array ie. images[] and imageDescriptions[]. My JSON looks like this:
{
"gallery" :
[
{
"id":"0001",
"galleryurl":"http://www.mysite.com/apps/wcbc/images/building0001.jpg",
"gallerydescr":"image description 1"
},
{
"id":"0002",
"galleryurl":"http://www.mysite.com/apps/wcbc/images/building00011.jpg",
"gallerydescr":"image description 2"
}
]
}
and I want the resulting images[] to look like this:
public static final String[] IMAGES = new String[] {
"http://www.mysite.com/apps/wcbc/images/building0001.jpg",
"http://www.mysite.com/apps/wcbc/images/building00011.jpg"
};
And here's my AsyncTask class where I want to parse the JSON into the String[]:
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
galleryArrList = new ArrayList<HashMap<String, String>>();
JGrid4Adapter jParser = new JGrid4Adapter();
// getting JSON string from URL
JSONObject jsonOb = jParser.getJSONFromUrl(jsonUrl);
try {
JSArrGallery = jsonOb.getJSONArray(TAG_GALLERY);
// looping through All gallery images
for (int i = 0; i < JSArrGallery.length(); i++) {
JSONObject galleryJO = JSArrGallery.getJSONObject(i);
String idStr = galleryJO.getString(TAG_ID);
String urlStr = galleryJO.getString(TAG_GALLERYURL);
String descrStr = galleryJO.getString(TAG_GALLERYDESCR);
//-- How to create String Array at this point?
}// -- END for loop
} catch (JSONException e) {
e.printStackTrace();
}// --- END Try
return null;
}
@Override
protected void onPostExecute(Void args) {
//--- do stuff here
}
}
Any help would be cool.
class container { string id; string whatever; string someotherprop;}or at least array/list ofMap<String, ObjectOrString>