I have recently settup a php page on my server that runs through my database and outputs this onto the page.
JSONObject json = JSONfunctions.getJSONfromURL("http://abc.com/getjson.php");
try{
JSONArray myArray = json.getJSONArray("date");
for(int i=0;i<myArray.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = myArray.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("date", "date name:" + e.getString("date"));
map.put("activity", "activity: " + e.getString("activity"));
mylist.add(map);
}
http://abc.com/getjson.php outputs:
[{"date":"2012-04-23","activity":"gym"},{"date":"2012-04-24","activity":"walking"}]
parse json string as to get date :
because current json String Structure is
JSONArray -> JSONObject -> key-value.EDIT : you will need to change return type of
getJSONfromURLmethod toJSONArrayinstead ofJSONObjectbecause you are getting JSONArray as root element instead of JSONObject from server