1、使用Json不需要导入包,使用gson需要导入import com.google.gson.Gson;
下载地址:http://code.google.com/p/google-gson/downloads/detail?name=google-gson-2.2.4-release.zip
2、jsonString的书写格式
(1)解析数据
String jsonString="[{"name":"江磊","Id":"1109030115","age":20}]";
JsonReader jsonReader=new JsonReader(new StringReader(jsonString));
(2)从Json数据转换成对象
String jsonStringToUser="{"name":"江磊","Id":"1109030115","age":20}";
//注:是没有[]的,否则会出现java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY
User user=gson.fromJson(jsonStringToUser, User.class);
(3)从Json数据转换成对象List