Gson gson = new Gson(); String s = gson.toJson(自己的bean);
同理 list,map 都可以转string
list转string:
String list = gson.toJson(list);
map转string:
String map = gson.toJson(map);
在是bean转string的情况下,string 转 bean,list,map
HomeNavigatorBean homeNavigatorBean = gson.fromJson(s, HomeNavigatorBean.class);
自己的接收bean
string转list
List<Person> persons = gson.fromJson(list, new TypeToken<List<Person>>() {}.getType());
string转map
Map<String, Person> maps = gson.fromJson(map, new TypeToken<Map<String, Person>>() {}.getType());