android GSON的使用

1、json字符串转list 集合

Gson gson = new Gson();
if (!TextUtils.isEmpty(localContact)) {
            selectSortDtes = gson.fromJson(localContact, new TypeToken<List<ContactEntity.InfosBean.ListBean>>() {
            }.getType());
        }
localContact是JSON类型的字符串

2、list集合转json字符串

Gson gson = new Gson();
String tempContact = gson.toJson(selectSortDtes);

这里的gson最好是定义成全局变量

猜你喜欢

转载自blog.csdn.net/yann02/article/details/82457936