If you're going to work with JSON data, I recommend reviewing the JSON introduction at http://json.org, until it is thoroughly understood. Luckily, JSON is a relatively simple data format, and becoming comfortable with it comes quickly.
To the specific problem in the original question, note that the outer-most structure of the JSON data is an array. So, it needs to be read as an array -- not as an object.
Here's a brief description of the complete JSON structure.
An array with one element that is an unnamed object. The unnamed object has twelve elements, eleven of which are strings, and one of which, named "attributes", is an array of three objects. Each object in the "attributes" array has two string elements.
So, if you want the "attributes" array, first read in the entire contents as an array, then get the first component of the array as an object, then get the "attributes" element from that object as an array. Following is an example of doing this.
import java.math.BigDecimal;
import java.net.URI;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
public class Foo
{
public static void main(String[] args) throws Exception
{
JSONArray outerArray = new JSONArray("[{\"store_id\":\"81\",\"store_name\":\"Mayo - Castlebar McDrive\",\"store_type\":\"Drive-Thru\",\"vouchers_available\":\"Vouchers available\",\"store_limit\":\"10\",\"distance\":\"8123.33 km\",\"latitude\":\"53.8501090162671\",\"longitude\":\"-9.29713726043701\",\"image_name\":\"http:\\/\\/www.mcfinder.ie\\/admin\\/images\\/stores\\/default.png\",\"voucher_count\":\"2\",\"is_open\":\"Restaurant Open\",\"attributes\":[{\"attribute_name\":\"Wi-Fiiiii\",\"image_name\":\"http:\\/\\/www.mcfinder.ie\\/admin\\/images\\/attributes\\/t_wifi_icon.gif\"},{\"attribute_name\":\"Cashless\",\"image_name\":\"http:\\/\\/www.mcfinder.ie\\/admin\\/images\\/attributes\\/t_cashless_icon.gif\"},{\"attribute_name\":\"McDrive\",\"image_name\":\"http:\\/\\/www.mcfinder.ie\\/admin\\/images\\/attributes\\/car_icon.png\"}]}]");
JSONObject object = outerArray.getJSONObject(0);
JSONArray attributes = object.getJSONArray("attributes");
for (int i = 0, length = attributes.length(); i < length; i++)
{
JSONObject attribute = attributes.getJSONObject(i);
System.out.printf("attribute name=%s, image=%s\n", attribute.getString("attribute_name"), attribute.getString("image_name"));
}
}
}
If you're not stuck using the built-in JSON API that Android provides, I highly recommend switching to Jackson, which makes it very easy to read and write arbitrarily complex JSON with Java. Following is an example of using it.
import java.io.File;
import java.math.BigDecimal;
import java.net.URI;
import java.util.List;
import org.codehaus.jackson.map.ObjectMapper;
public class Foo
{
public static void main(String[] args) throws Exception
{
ObjectMapper mapper = new ObjectMapper();
Store[] stores = mapper.readValue(new File("input.json"), Store[].class);
Store store = stores[0];
List<Attribute> attributes = store.attributes;
for (Attribute attribute : attributes)
{
System.out.printf("attribute name=%s, image=%s\n", attribute.attribute_name, attribute.image_name);
}
// output:
// attribute name=Wi-Fiiiii, image=http://www.mcfinder.ie/admin/images/attributes/t_wifi_icon.gif
// attribute name=Cashless, image=http://www.mcfinder.ie/admin/images/attributes/t_cashless_icon.gif
// attribute name=McDrive, image=http://www.mcfinder.ie/admin/images/attributes/car_icon.png
}
}
class Store
{
public String store_id;
public String store_name;
public String store_type;
public String vouchers_available;
public String store_limit;
public String distance;
public BigDecimal latitude;
public BigDecimal longitude;
public URI image_name;
public int voucher_count;
public String is_open;
public List<Attribute> attributes;
}
class Attribute
{
public String attribute_name;
public URI image_name;
}