目录
FastJson简介
fastjson是阿里巴巴开源的JSON处理工具。
开源地址为:Github
使用
添加 compile 'com.alibaba:fastjson:1.1.64.android'
String json = "{\"text1\":\"1111\",\"text2\":2222222}";
Access access = JSON.parSEObject(json,Access.class);
Log.e(TAG,"access:" + access.tostring());
Access access = new Access("第一个参数","第二个参数");
Log.e(TAG,JSON.toJSONString(access));
List转Json
List<Access> list = new arraylist();
Access access = new Access("第一个参数","第二个参数");
list.add(access);
list.add(access);
list.add(access);
list.add(access);
Log.e(TAG,JSON.toJSON(list).toString());
Json转List
String json = "[{\"text1\":\"woshishui\",\"text2\":\"dierge\"},{\"text1\":\"woshishui\",\"text2\":\"dierge\"}]";
List<Access> list = JSON.parseArray(json,Access.class);
for (int i = 0; i < list.size(); i++){
Log.e(TAG + i + "",list.get(i).toString());
}