Android学习笔记_14_对JSON格式数据的处理
public class ParseJsonTest extends AndroidTestCase{ public void testJson() throws Exception { String userlist = "[{id:1001,name:\"tom\",age:22},{id:1002,name:\"tom1\",age:26}]"; List<Person> persons = new ArrayList<Person>(); JSONArray jsonArray = new JSONArray(userlist); for (int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); Person person = new Person(object.getInt("id"), object.getString("name"), object.getInt("age")); persons.add(person); } for (Person person : persons) { Log.i("ParseJsonTest", person.toString()); } } }