Last active
December 17, 2015 09:48
-
-
Save anttti/5589454 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private String getPersonsAsJSON(List<Person> personList) throws JSONException { | |
JSONObject json = new JSONObject(); | |
JSONArray jsonPeopleList = new JSONArray(); | |
if (personList != null) { | |
for (Person p : personList) { | |
JSONObject personJson = new JSONObject(); | |
personJson.put("firstname", p.getFirstName()); | |
personJson.put("lastname", p.getLastName()); | |
personJson.put("email", p.getEmail()); | |
jsonPeopleList.put(personJson); | |
} | |
} | |
json.put("people", jsonPeopleList); | |
String jsonStr = json.toString(); | |
Log.i(TAG, "Persons as JSON: " + jsonStr); | |
return jsonStr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment