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());
}
}
}
上一篇:Android学习笔记七:五大存储


下一篇:SpringBoot添加对Mybatis的支持