Created
February 17, 2012 19:40
-
-
Save smoak/1855071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// assumes you have already gotten this json back from an Http server: | |
// [{"id":1,"firstName":"j","lastName":"v"},{"id":2,"firstName":"Dr. a","lastName":"b"}] | |
// and stored it in a String called json | |
JSONArray json = new JSONArray(json); | |
// loop over each individual json object: | |
// a single json object looks like: {"id":1,"firstName":"j","lastName":"v"} | |
int count = json.length(); | |
for (int i = 0; i < count; i++) { | |
JSONObject jsonObj = json.getJSONObject(i); | |
// now we can access the individual keys | |
// in the jsonObj: | |
int id = jsonObj.getInt("id"); | |
String firstName = jsonObj.getString("firstName"); | |
String lastName = jsonObj.getString("lastName"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment