1.配置依赖
//fastjson api 'com.alibaba:fastjson:1.2.44'
2.设计服务端返回的数据
{"result":"success","data":[{"name":"mike1","age":11},{"name":"mike2","age":22},{"name":"mike3","age":33}]}
3.编写bean类,特别注意,要和服务端返回的类型一致,并且都要public
public class User { public String result; public List<Data> data; public class Data{ public String name; public int age; public String getName() { return name; } public int getAge() { return age; } } public String getResult() { return result; } public List<Data> getDatas() { return data; } }
4.解析数据
//json就是返回的数据 User user = JSON.parseObject(json,User.class); Log.d(TAG, "onResponse: "+user.getDatas().get(0).getName());
完成,下面要讲下子线程怎么更新主线程的UI,