android 集合类与json字符串之间的转换

从 https://code.google.com/p/google-gson/downloads/list下载 gson jar包

在  https://code.google.com/p/google-gson/downloads/list 页面找到 javadoc api 文档 

Gson gson=new Gson();

List listobject=new ArrayList();

集合转换成json字符串

String jsonstr=gson.tojson(listobject);

字符串转换成集合

首先获取集合类型     Type       Type is the common superinterface for all types in the Java programming language

type 适用于java 的所有数据类型

通过匿名类实现获取type

 Type type=new  TypeToken>().{}getType();   

listobject=gson.fromJson(jsonstr,type);

 

你可能感兴趣的:(Android,开发)